Yocto Project Documentation
 help / color / mirror / Atom feed
From: Trevor Woerner <twoerner@gmail.com>
To: docs@lists.yoctoproject.org
Subject: [PATCH 02/10] docs: copy only the command from a console block
Date: Mon, 21 Sep 2026 22:03:31 -0400	[thread overview]
Message-ID: <20260922020339.481929-3-twoerner@gmail.com> (raw)
In-Reply-To: <20260922020339.481929-1-twoerner@gmail.com>

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,
output included. Match a pattern covering each prompt shape the manuals
use instead, and stop the mouse selecting the output, so both ways of
copying give the commands alone.

AI-Generated: codex/claude-opus 5 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
 documentation/conf.py                         | 21 ++++++++++++++++++-
 .../sphinx-static/theme_overrides.css         |  9 ++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/documentation/conf.py b/documentation/conf.py
index 48d28a686807..ccec27e60165 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -242,4 +242,23 @@ intersphinx_mapping = {
 # -- sphinx_copybutton configuration -----------------------------------------
 
 # sphinx-copybutton configuration
-copybutton_prompt_text = "$ "
+# 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 = "\\"
diff --git a/documentation/sphinx-static/theme_overrides.css b/documentation/sphinx-static/theme_overrides.css
index f9e067239b8e..1a439e9faf69 100644
--- a/documentation/sphinx-static/theme_overrides.css
+++ b/documentation/sphinx-static/theme_overrides.css
@@ -107,6 +107,15 @@ section#welcome-to-the-yocto-project-documentation p.caption {
    display: none;
 }
 
+/* Sphinx already excludes the prompt from a selection; do the same for the
+   output, so selecting a session block gives what the copy button gives */
+.highlight span.go {
+    user-select: none;
+    -webkit-user-select: none;
+    -moz-user-select: none;
+    -ms-user-select: none;
+}
+
 @media screen {
     .wy-nav-content {
        max-width: 1000px;
-- 
2.50.0.173.g8b6f19ccfc3a



  parent reply	other threads:[~2026-09-22  2:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  2:03 [PATCH 00/10] docs: editorial repairs to the examples Trevor Woerner
2026-09-22  2:03 ` [PATCH 01/10] docs: give the root prompts a preamble Trevor Woerner
2026-09-22  2:03 ` Trevor Woerner [this message]
2026-09-22 12:20   ` [docs] [PATCH 02/10] docs: copy only the command from a console block Antonin Godard
2026-09-22 14:40     ` Trevor Woerner
2026-09-22 15:16       ` Antonin Godard
2026-09-22  2:03 ` [PATCH 03/10] docs: show a prompt on commands the reader is meant to type Trevor Woerner
2026-09-22 12:19   ` [docs] " Antonin Godard
2026-09-22 14:23     ` Trevor Woerner
2026-09-22  2:03 ` [PATCH 04/10] docs: write an elided passage as a comment Trevor Woerner
2026-09-22  2:03 ` [PATCH 05/10] docs: mark the placeholders in examples Trevor Woerner
2026-09-22  2:03 ` [PATCH 06/10] docs: remove real accounts from the examples Trevor Woerner
2026-09-22  2:03 ` [PATCH 07/10] kernel-dev: give each example block one thing to hold Trevor Woerner
2026-09-22 12:19   ` [docs] " Antonin Godard
2026-09-22  2:03 ` [PATCH 08/10] ref-manual: put the ARCHIVER_MODE comments on their own lines Trevor Woerner
2026-09-22  2:03 ` [PATCH 09/10] ref-manual: drop "partition" as a wic kickstart command Trevor Woerner
2026-09-22 12:19   ` [docs] " Antonin Godard
2026-09-22  2:03 ` [PATCH 10/10] dev-manual: indent a list continuation so the code block ends Trevor Woerner
2026-09-22 12:19   ` [docs] " Antonin Godard
2026-09-22 12:19 ` [docs] [PATCH 00/10] docs: editorial repairs to the examples Antonin Godard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260922020339.481929-3-twoerner@gmail.com \
    --to=twoerner@gmail.com \
    --cc=docs@lists.yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox