Skip to content

Commit ef3c552

Browse files
committed
Improve the highlight class injection
1 parent 2732143 commit ef3c552

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Doc/tools/extensions/grammar_snippet.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
from sphinx.domains.std import token_xrefs
99

1010

11+
class snippet_literal_string(nodes.inline):
12+
"""Node for a string literal in a grammar snippet."""
13+
14+
def __init__(self) -> None:
15+
# Use the Pygments highlight class for `Literal.String.Other`
16+
super().__init__(classes=['sx'])
17+
18+
1119
class GrammarSnippetBase(SphinxDirective):
1220
"""Common functionality for GrammarSnippetDirective & CompatProductionList."""
1321

@@ -31,8 +39,6 @@ def make_grammar_snippet(self, options, content):
3139
literal = nodes.literal_block(
3240
rawsource,
3341
'',
34-
# TODO: Use a dedicated CSS class here and for strings.
35-
# and add it to the theme too
3642
classes=['highlight'],
3743
)
3844

@@ -70,7 +76,7 @@ def make_grammar_snippet(self, options, content):
7076
case {'rule_ref': ref_text}:
7177
literal += token_xrefs(ref_text, group_name)
7278
case {'single_quoted': name} | {'double_quoted': name}:
73-
string_node = nodes.inline(classes=['nb'])
79+
string_node = snippet_literal_string()
7480
string_node += nodes.Text(name)
7581
literal += string_node
7682
case _:

0 commit comments

Comments
 (0)