https://github.com/python/cpython/commit/19270d3bbb58c08a97bd9b481655adf42bdfbe3c
commit: 19270d3bbb58c08a97bd9b481655adf42bdfbe3c
branch: main
author: Aurora-NICExq <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-10-28T16:03:04Z
summary:

gh-142714: Exclude stripped PEG grammar text from translation catalogs (#159305)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
M Doc/tools/extensions/lexers/__init__.py

diff --git a/Doc/tools/extensions/lexers/__init__.py 
b/Doc/tools/extensions/lexers/__init__.py
index e12ac5be8139cc2..580ec172d876f99 100644
--- a/Doc/tools/extensions/lexers/__init__.py
+++ b/Doc/tools/extensions/lexers/__init__.py
@@ -1,12 +1,34 @@
+from docutils import nodes
+from sphinx.transforms import SphinxTransform
+
 from .asdl_lexer import ASDLLexer
 from .peg_lexer import PEGLexer
 
 
+class StripPEGBlocks(SphinxTransform):
+    # Strip PEG blocks like PEGLexer does when highlighting them, so that
+    # other builders (gettext in particular) get the text the page shows.
+    # Must run before the i18n Locale transform (20).
+    default_priority = 10
+
+    def apply(self):
+        lexer = PEGLexer()
+        for node in self.document.findall(nodes.literal_block):
+            if node.get("language") != "peg":
+                continue
+            tokens = lexer.get_tokens_unprocessed(node.rawsource)
+            text = "".join(value for _, _, value in tokens)
+            node.rawsource = text
+            node[:] = [nodes.Text(text)]
+
+
 def setup(app):
     # Used for highlighting Parser/Python.asdl in library/ast.rst
     app.add_lexer("asdl", ASDLLexer)
     # Used for highlighting Grammar/python.gram in reference/grammar.rst
     app.add_lexer("peg", PEGLexer)
+    # Strips hidden grammar parts before translation catalogs are built
+    app.add_transform(StripPEGBlocks)
 
     return {
         "version": "1.0",

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to