Skip to content
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
Expand Up @@ -8,6 +8,14 @@
from sphinx.domains.std import token_xrefs


class snippet_literal_string(nodes.inline):
"""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 @@ def make_grammar_snippet(self, options, content):
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 @@ def make_grammar_snippet(self, options, content):
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