diff mbox series

[v3,02/10] docs: copy only the command from a console block

Message ID 20260924172853.2665062-3-twoerner@gmail.com
State New
Headers show
Series docs: editorial repairs to the examples | expand

Commit Message

Trevor Woerner Sept. 24, 2026, 5:28 p.m. UTC
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 v3:
- the comment is shorter and no longer contradicts itself about scope
- a ">>> " alternative covers the one Python interpreter example
- a "(gdb) " alternative. The console lexer already marks that prompt,
  so a selection skipped it while the button copied it; the two now
  agree

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 | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/documentation/conf.py b/documentation/conf.py
index 48d28a686807..d2252d5ab966 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -242,4 +242,21 @@  intersphinx_mapping = {
 # -- sphinx_copybutton configuration -----------------------------------------
 
 # sphinx-copybutton configuration
-copybutton_prompt_text = "$ "
+# Applies to the copy button only; a mouse selection is untouched.
+# Not scoped to console blocks, so every alternative has to be safe in a
+# BitBake or configuration example too.
+# No rule for a bare "#": it opens a comment, a root prompt, and a
+# line of program output alike.
+copybutton_prompt_text = "|".join((
+    r"^(?:\S+[@:]\S*)?\$\s+",   # "$ ", and "user@host:~$ "
+    r"^\S+[@:]\S*#\s+",         # "root@machine:~# ", 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
+    r"^>>> ",                   # a Python interpreter session
+    r"^\(gdb\)\s+",             # a gdb session
+))
+copybutton_prompt_is_regexp = True
+copybutton_only_copy_prompt_lines = True
+copybutton_remove_prompts = True
+copybutton_line_continuation_character = "\\"