https://github.com/python/cpython/commit/b84964788ead8a0a8bc8dcce78ccb7fd8cc76861 commit: b84964788ead8a0a8bc8dcce78ccb7fd8cc76861 branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-10-29T09:29:06Z summary:
[3.14] gh-142714: Exclude stripped PEG grammar text from translation catalogs (GH-159305) (#160834) (cherry picked from commit 19270d3bbb58c08a97bd9b481655adf42bdfbe3c) Co-authored-by: Aurora-NICExq <[email protected]> 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]
