Skip to content

Don't copy >>> characters from pycon fenced codeblocks #3647

@mondeja

Description

@mondeja

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

When using a fenced pycon codeblock (Python console syntax highlighting) the >>> characters can be skipped of being manually selected using the next custom CSS as is documented in mkdocstrings:

.highlight .gp, .highlight .go { /* Generic.Prompt, Generic.Output */
    user-select: none;
}

But clicking in the "Copy to clipboard button", it copies the whole line, including the >>> part, which is not desirable for pycon code blocks. It seems that ClipboardJS offers a way to edit the content that is copied.

It should be reasonable to add more logic to the clipboard component? Maybe checking the CSS of the text and skipping all the content styled with user-select: none;? Thanks in advance!

Expected behaviour

Copying pycon fenced code blocks should not include >>> Python console characters.

Actual behaviour

Undesired characters are copied.

Steps to reproduce

N/A

Package versions

All

Configuration

markdown_extensions:
  - pymdownx.highlight:
      use_pygments: true
  - pymdownx.superfences

extra_css:
  - css/code_select.css

System information

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions