| Message ID | 20260922183249.2433345-3-twoerner@gmail.com |
|---|---|
| State | Accepted |
| Headers | show |
| Series | docs: editorial repairs to the examples | expand |
Hi Trevor, On 9/22/26 8:32 PM, Trevor Woerner via lists.yoctoproject.org wrote: > The copy button matches the literal "$ " prompt, so on a block prompted > any other way it matches nothing and falls back to copying every line, > prompt and output included. Match a pattern covering each prompt shape > the manuals use instead, so the button gives the command alone whatever > the prompt looks like. > > AI-Generated: codex/claude-opus 5 (xhigh) > Signed-off-by: Trevor Woerner <twoerner@gmail.com> > --- > changes in v2: > - dropped the stylesheet change, so a mouse selection keeps the output > - the comment now says this governs the copy button only, and only > reaches a block the console lexer has read > --- > documentation/conf.py | 28 +++++++++++++++++++++++++++- > 1 file changed, 27 insertions(+), 1 deletion(-) > > diff --git a/documentation/conf.py b/documentation/conf.py > index 48d28a686807..313cabec05bb 100644 > --- a/documentation/conf.py > +++ b/documentation/conf.py > @@ -242,4 +242,30 @@ intersphinx_mapping = { > # -- sphinx_copybutton configuration ----------------------------------------- > > # sphinx-copybutton configuration > -copybutton_prompt_text = "$ " > +# This governs the copy button only. A mouse selection is a separate > +# mechanism and takes whatever the theme leaves selectable, which is the > +# command and its output; Sphinx already excludes the prompt itself. > +# > +# It also only reaches a block the console lexer read, since that is what > +# marks a prompt as a prompt. > +# > +# Strip the prompt from a copied line wherever the prompt cannot be > +# confused with content. The pattern is not scoped to console blocks, so You say above that it only reaches blocks the console lexer reads and now you say it's not scoped to console blocks, this is confusing. > +# every alternative has to stay safe inside a BitBake or configuration > +# example as well; measured over the built manuals, each one matches only > +# lines the lexer itself marks as a prompt. > +# > +# A bare "#" is deliberately absent. It opens a root prompt, a comment and > +# a line of program output alike, and nothing distinguishes them - which is > +# why the root prompts are given a preamble before this is switched on. Ask your AI to be less verbose please, or edit the comments by hand. In 10s I could come up with: # Only applies to the copybutton. Mouse selection is not impacted. # <insert whatever is correct for the pattern scope> # No rule for # as it can denote a comment, root prompt or command output. > +copybutton_prompt_text = "|".join(( > + r"^(?:\S+[@:]\S*)?\$\s+", # "$ ", and "user@host:~$ " Am I right that (?:) is just to say "do not capture the content" (c.f. https://docs.python.org/3/library/re.html#regular-expression-syntax). Is it *really* necessary, I find that it adds unnecessary complexity for a human to maintain this regexp. EDIT: sigh... copybutton is parsing with Javascript according to https://sphinx-copybutton.readthedocs.io/en/latest/use.html#using-regexp-prompt-identifiers but regex101.com says the same (non-capturing group). > + r"^\S+[@:]\S*#\s+", # "root@qemux86-64:~# ", a root prompt And then you could simply merge the two first regexp into one: r"^\S+[@:]\S*[#\$]\s+" > + r"^[A-Za-z]:\\[^>]*>\s*", # "C:\WINDOWS\system32>", cmd.exe Have not used Windows in 15 years so cannot say whether this is appropriate. In any case, I'm not sure we'll have more examples than we have today for Windows as only the WSL part would use that, so fine with me. > + r"^DISKPART>\s*", # diskpart prints a prompt of its own > + r"^pydevshell>\s+", # bitbake -c pydevshell question: what happens to the one and only example we have of commands to run in a python interpreter? (remove the leading #, it's just so mail clients don't interpret this as a quote of a quote of a quote) # >>> from gi.repository import GLib # >>> GLib.get_host_name() > +)) > +copybutton_prompt_is_regexp = True > +copybutton_only_copy_prompt_lines = True This is the default, but I'm guessing it doesn't hurt to make it explicit. > +copybutton_remove_prompts = True This is the default, but I'm guessing it doesn't hurt to make it explicit. Cheers, Quentin
On 9/23/26 12:41 PM, Quentin Schulz via lists.yoctoproject.org wrote: > Hi Trevor, > > On 9/22/26 8:32 PM, Trevor Woerner via lists.yoctoproject.org wrote: >> The copy button matches the literal "$ " prompt, so on a block prompted >> any other way it matches nothing and falls back to copying every line, >> prompt and output included. Match a pattern covering each prompt shape >> the manuals use instead, so the button gives the command alone whatever >> the prompt looks like. >> >> AI-Generated: codex/claude-opus 5 (xhigh) >> Signed-off-by: Trevor Woerner <twoerner@gmail.com> >> --- >> changes in v2: >> - dropped the stylesheet change, so a mouse selection keeps the output >> - the comment now says this governs the copy button only, and only >> reaches a block the console lexer has read >> --- >> documentation/conf.py | 28 +++++++++++++++++++++++++++- >> 1 file changed, 27 insertions(+), 1 deletion(-) >> >> diff --git a/documentation/conf.py b/documentation/conf.py >> index 48d28a686807..313cabec05bb 100644 >> --- a/documentation/conf.py >> +++ b/documentation/conf.py >> @@ -242,4 +242,30 @@ intersphinx_mapping = { >> # -- sphinx_copybutton configuration >> ----------------------------------------- >> # sphinx-copybutton configuration >> -copybutton_prompt_text = "$ " >> +# This governs the copy button only. A mouse selection is a separate >> +# mechanism and takes whatever the theme leaves selectable, which is the >> +# command and its output; Sphinx already excludes the prompt itself. >> +# >> +# It also only reaches a block the console lexer read, since that is >> what >> +# marks a prompt as a prompt. >> +# >> +# Strip the prompt from a copied line wherever the prompt cannot be >> +# confused with content. The pattern is not scoped to console blocks, so > > You say above that it only reaches blocks the console lexer reads and > now you say it's not scoped to console blocks, this is confusing. > >> +# every alternative has to stay safe inside a BitBake or configuration >> +# example as well; measured over the built manuals, each one matches >> only >> +# lines the lexer itself marks as a prompt. >> +# >> +# A bare "#" is deliberately absent. It opens a root prompt, a >> comment and >> +# a line of program output alike, and nothing distinguishes them - >> which is >> +# why the root prompts are given a preamble before this is switched on. > > Ask your AI to be less verbose please, or edit the comments by hand. > > In 10s I could come up with: > > # Only applies to the copybutton. Mouse selection is not impacted. > # <insert whatever is correct for the pattern scope> > # No rule for # as it can denote a comment, root prompt or command output. > >> +copybutton_prompt_text = "|".join(( >> + r"^(?:\S+[@:]\S*)?\$\s+", # "$ ", and "user@host:~$ " > > Am I right that (?:) is just to say "do not capture the content" (c.f. > https://eur02.safelinks.protection.outlook.com/? > url=https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fre.html%23regular- > expression- > syntax&data=05%7C02%7Cquentin.schulz%40cherry.de%7Cb7040e79d7cc4140b6d908df195f3dfa%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C639257569068945587%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ep8uCE%2BFE3tcdhzUT3Xt0wc4KdQytvOjxMP%2FUkvXtmk%3D&reserved=0). Is it *really* necessary, I find that it adds unnecessary complexity for a human to maintain this regexp. > > EDIT: sigh... copybutton is parsing with Javascript according to > https://eur02.safelinks.protection.outlook.com/? > url=https%3A%2F%2Fsphinx- > copybutton.readthedocs.io%2Fen%2Flatest%2Fuse.html%23using-regexp- > prompt- > identifiers&data=05%7C02%7Cquentin.schulz%40cherry.de%7Cb7040e79d7cc4140b6d908df195f3dfa%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C639257569068971255%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=lo7H8RTXJ%2FjVWkfjWeOk7xuIapQowSevjLwFHmWwukM%3D&reserved=0 but regex101.com says the same (non-capturing group). > >> + r"^\S+[@:]\S*#\s+", # "root@qemux86-64:~# ", a root prompt > > And then you could simply merge the two first regexp into one: > > r"^\S+[@:]\S*[#\$]\s+" > OK this isn't what you want, because this here will match not match a line starting with $ and if we reuse the regexp from above, then it would match a line starting with #, which we don't want. So having them split is fine. Ignore this comment. >> + r"^[A-Za-z]:\\[^>]*>\s*", # "C:\WINDOWS\system32>", cmd.exe > > Have not used Windows in 15 years so cannot say whether this is > appropriate. In any case, I'm not sure we'll have more examples than we > have today for Windows as only the WSL part would use that, so fine with > me. > >> + r"^DISKPART>\s*", # diskpart prints a prompt of its own >> + r"^pydevshell>\s+", # bitbake -c pydevshell > > question: what happens to the one and only example we have of commands > to run in a python interpreter? (remove the leading #, it's just so mail > clients don't interpret this as a quote of a quote of a quote) > > # >>> from gi.repository import GLib > # >>> GLib.get_host_name() > >> +)) >> +copybutton_prompt_is_regexp = True >> +copybutton_only_copy_prompt_lines = True > > This is the default, but I'm guessing it doesn't hurt to make it explicit. > >> +copybutton_remove_prompts = True > > This is the default, but I'm guessing it doesn't hurt to make it explicit. > > Cheers, > Quentin > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#10602): https://lists.yoctoproject.org/g/docs/message/10602 > Mute This Topic: https://lists.yoctoproject.org/mt/121380214/6293953 > Group Owner: docs+owner@lists.yoctoproject.org > Unsubscribe: https://lists.yoctoproject.org/g/docs/unsub [quentin.schulz@cherry.de] > -=-=-=-=-=-=-=-=-=-=-=- >
diff --git a/documentation/conf.py b/documentation/conf.py index 48d28a686807..313cabec05bb 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -242,4 +242,30 @@ intersphinx_mapping = { # -- sphinx_copybutton configuration ----------------------------------------- # sphinx-copybutton configuration -copybutton_prompt_text = "$ " +# This governs the copy button only. A mouse selection is a separate +# mechanism and takes whatever the theme leaves selectable, which is the +# command and its output; Sphinx already excludes the prompt itself. +# +# It also only reaches a block the console lexer read, since that is what +# marks a prompt as a prompt. +# +# Strip the prompt from a copied line wherever the prompt cannot be +# confused with content. The pattern is not scoped to console blocks, so +# every alternative has to stay safe inside a BitBake or configuration +# example as well; measured over the built manuals, each one matches only +# lines the lexer itself marks as a prompt. +# +# A bare "#" is deliberately absent. It opens a root prompt, a comment and +# a line of program output alike, and nothing distinguishes them - which is +# why the root prompts are given a preamble before this is switched on. +copybutton_prompt_text = "|".join(( + r"^(?:\S+[@:]\S*)?\$\s+", # "$ ", and "user@host:~$ " + r"^\S+[@:]\S*#\s+", # "root@qemux86-64:~# ", a root prompt + r"^[A-Za-z]:\\[^>]*>\s*", # "C:\WINDOWS\system32>", cmd.exe + r"^DISKPART>\s*", # diskpart prints a prompt of its own + r"^pydevshell>\s+", # bitbake -c pydevshell +)) +copybutton_prompt_is_regexp = True +copybutton_only_copy_prompt_lines = True +copybutton_remove_prompts = True +copybutton_line_continuation_character = "\\"
The copy button matches the literal "$ " prompt, so on a block prompted any other way it matches nothing and falls back to copying every line, prompt and output included. Match a pattern covering each prompt shape the manuals use instead, so the button gives the command alone whatever the prompt looks like. AI-Generated: codex/claude-opus 5 (xhigh) Signed-off-by: Trevor Woerner <twoerner@gmail.com> --- changes in v2: - dropped the stylesheet change, so a mouse selection keeps the output - the comment now says this governs the copy button only, and only reaches a block the console lexer has read --- documentation/conf.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)