All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trevor Woerner <twoerner@gmail.com>
To: docs@lists.yoctoproject.org
Subject: [PATCH 6/7] sphinx: read a bare "#" in a console block as output
Date: Wed, 25 Nov 2026 10:45:34 -0500	[thread overview]
Message-ID: <20261125154535.3486104-7-twoerner@gmail.com> (raw)
In-Reply-To: <20261125154535.3486104-1-twoerner@gmail.com>

Pygments treats "$", "#", and "%" alike as prompts and lets the preamble
before them be empty, so a line opening with "#" is taken for a root
prompt and the rest of it is lexed as the command it introduces. Across
these manuals that line is a comment or a line of program output every
time, never a prompt: a root prompt carries the host preamble saying
whose root it is.

Require that preamble before a "#". The line then falls through to
Generic.Output, which is what it was, and the theme stops showing
perf headers and generated-file comments as commands somebody typed.

AI-Generated: codex/claude-opus 5.5 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
 documentation/conf.py                 |  3 +-
 documentation/sphinx/console-lexer.py | 53 +++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/console-lexer.py

diff --git a/documentation/conf.py b/documentation/conf.py
index 3a7e3c920fc4..5db20ff021fc 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -84,7 +84,8 @@ extensions = [
     'bitbake-placeholder',
     'scc-lexer',
     'wks-lexer',
-    'pydevshell-lexer'
+    'pydevshell-lexer',
+    'console-lexer'
 ]
 
 # current_version = "dev"
diff --git a/documentation/sphinx/console-lexer.py b/documentation/sphinx/console-lexer.py
new file mode 100644
index 000000000000..0f9eaa4ce33e
--- /dev/null
+++ b/documentation/sphinx/console-lexer.py
@@ -0,0 +1,53 @@
+"""A console session lexer that reads a bare ``#`` as output, not a prompt.
+
+Pygments treats ``$``, ``#``, and ``%`` alike and allows the preamble
+before them to be empty, so a line beginning ``#`` is a root prompt and
+the rest of the line is lexed as the command it introduces. In these
+manuals that is wrong far more often than it is right: a ``#`` opening a
+line is a comment or a line of program output, and a root prompt carries
+the ``user@host:path`` preamble that says whose root it is.
+
+Requiring that preamble before a ``#`` is the whole of the change.
+``$`` and ``%`` keep Pygments' behaviour exactly, bare prompt included.
+A line that is no longer a prompt falls through to ``Generic.Output``,
+which is what it always was.
+
+This is a local convention rather than a universal one - outside these
+manuals a bare ``#`` really is how a root shell prompts - so it belongs
+here and not upstream.
+"""
+import re
+
+from pygments.lexers.shell import BashSessionLexer
+
+__version__ = '1.0'
+
+# Pygments' own preamble alternation, spelled twice: once as it has it,
+# and once with the empty branch removed. Keeping its wording rather than
+# writing a tidier one means a prompt shape it learns later still works.
+_PREAMBLE = (r'(?:\[.*?\])|(?:\(\S+\))?'
+             r'(?:| |sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)?|\[\S+[@:][^\n]+\].+)')
+_NAMED = (r'(?:\[.*?\])|(?:\(\S+\))?'
+          r'(?:sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)?|\[\S+[@:][^\n]+\].+)')
+
+
+class ConsoleSessionLexer(BashSessionLexer):
+    """A console session in which a bare ``#`` is not a root prompt."""
+
+    name = 'Console session'
+    aliases = ['console']
+    filenames = []
+    mimetypes = []
+
+    _ps1rgx = re.compile(
+        r'^((?:' + _PREAMBLE + r')\s*[$%]\s*'
+        r'|(?:' + _NAMED + r')\s*#\s*)(.*\n?)')
+
+
+def setup(app):
+    app.add_lexer('console', ConsoleSessionLexer)
+    return {
+        'version': __version__,
+        'parallel_read_safe': True,
+        'parallel_write_safe': True,
+    }
-- 
2.50.0.173.g8b6f19ccfc3a


  parent reply	other threads:[~2026-11-25 15:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
2026-11-25 15:45 ` [PATCH 1/7] sphinx: carry a BitBake lexer as a local extension Trevor Woerner
2026-11-25 15:45 ` [PATCH 2/7] sphinx: add a lexer for BitBake with placeholders Trevor Woerner
2026-11-25 15:45 ` [PATCH 3/7] sphinx: add a lexer for kernel metadata SCC files Trevor Woerner
2026-11-25 15:45 ` [PATCH 4/7] sphinx: add a lexer for wic kickstart files Trevor Woerner
2026-11-25 15:45 ` [PATCH 5/7] sphinx: add a lexer for pydevshell sessions Trevor Woerner
2026-11-25 15:45 ` Trevor Woerner [this message]
2026-11-25 15:45 ` [PATCH 7/7] sphinx: mark placeholders in console and plain-text examples Trevor Woerner
2026-11-26 16:33 ` [docs] [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Antonin Godard
2026-11-26 22:26   ` Trevor Woerner

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=20261125154535.3486104-7-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.