Skip to content

Conflict between regex exclusion/prompt selection and copybutton_exclude #185

Open
@rkdarst

Description

@rkdarst

From #178 (comment) .

Describe the bug

There are now two ways to avoid copying prompts and output:

  1. copybutton_exclude excludes certain CSS classes. Sphinx uses this by default to prevent selection of prompts.
  2. copybutton_prompt_text, copybutton_only_copy_prompt_lines, copybutton_remove_prompts, copybutton_copy_empty_lines.

(1) is in theory automatic: the Pygments lexer should highlights prompts with the class .gp, and outputs with the class .go. Right now, the default exclusion is .linenos, .gp. You have to remember to use the right lexer, for example "Python console" instead of "Python" or "console" instead of "bash".

(2) is manually configured to certain programming languages, per Sphinx project.

The conflict is that (1) removes the prompt text, so that certain features of (2) don't see the prompt regex, so that copybutton_only_copy_prompt_lines no longer works by default. Workarounds:

  • copybutton_exclude = '.linenos' or
  • (I haven't check if this works) add .go to copybutton_exclude and set copybutton_copy_empty_lines = False

I can think of two strategies to do:

a) undo the chaneg in defaults, switch copybutton_exclude to .linenos by default (this previous default). In order to exclude prompt and output, everyone needs to configure it by either strategy (1) or (2) above. Document these two options and the choices. Disadvantages: doesn't work out of the box for anyone, not even "a bit better" than default. Copybutton has worse default behavior than Sphinx.

b) Go further towards copybutton_exclude. Set default to .linenos, .gp, .go to exclude the console output, too (or document how to do this). Set copybutton_copy_empty_lines = False by default. Encourage people to use the right lexers and fix broken lexers (sphinx has good support for this). Documentation is updated for how to set `copybutton_exclude '.linenos' to turn this off and only use with regexps.

  • Disadvantages: diverges from the default Sphinx behavior (it does .linesnos, .gp). There are valid reasons to copy the output, and not being able to do this is confusing (but more so than not being able to copy the prompt? It assumes no one wants to copy outputs, which probably isn't true, but one could always change the lexer to plain text if one wants it to not be treated as console).
  • Advantages: by default, if you specify the right language, it Just Works.
  • TODO: But we need to check the "copy bduplicated lines" thing.

Incidentally, I thought that pygments included an IPython lexer, but couldn't find it. In fact, it seems that it does - but is distributed with IPython itself, and seems to use Generic.Prompt and Generic.Output.

I will update this description as I find more facts.

Reproduce the bug

Use the things above, I will try to create a test case later.

List your environment

latest release

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions