Skip to content

gh-127833: Docs: Add a grammar-snippet directive & replace productionlist #127835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve the highlight class injection
  • Loading branch information
encukou committed Jan 29, 2025
commit ef3c552a3636dbdc20e4753f55b6c8cae89336c3
12 changes: 9 additions & 3 deletions Doc/tools/extensions/grammar_snippet.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import re

from docutils import nodes
from docutils.parsers.rst import directives
from sphinx import addnodes
from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_id
from sphinx.domains.std import token_xrefs


class snippet_literal_string(nodes.inline):

Check failure on line 11 in Doc/tools/extensions/grammar_snippet.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

Doc/tools/extensions/grammar_snippet.py:1:1: I001 Import block is un-sorted or un-formatted

Check failure on line 11 in Doc/tools/extensions/grammar_snippet.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (N801)

Doc/tools/extensions/grammar_snippet.py:11:7: N801 Class name `snippet_literal_string` should use CapWords convention
"""Node for a string literal in a grammar snippet."""

def __init__(self) -> None:
# Use the Pygments highlight class for `Literal.String.Other`
super().__init__(classes=['sx'])


class GrammarSnippetBase(SphinxDirective):
"""Common functionality for GrammarSnippetDirective & CompatProductionList."""

Expand All @@ -31,8 +39,6 @@
literal = nodes.literal_block(
rawsource,
'',
# TODO: Use a dedicated CSS class here and for strings.
# and add it to the theme too
classes=['highlight'],
)

Expand Down Expand Up @@ -70,7 +76,7 @@
case {'rule_ref': ref_text}:
literal += token_xrefs(ref_text, group_name)
case {'single_quoted': name} | {'double_quoted': name}:
string_node = nodes.inline(classes=['nb'])
string_node = snippet_literal_string()
string_node += nodes.Text(name)
literal += string_node
case _:
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy