Skip to content

Commit 74b21f7

Browse files
authored
👌 Add render_math_block_label for docutils (#668)
1 parent 2a5bd61 commit 74b21f7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

myst_parser/mdit_to_docutils/base.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,16 @@ def render_math_block(self, token: SyntaxTreeNode) -> None:
10511051
self.add_line_and_source_path(node, token)
10521052
self.current_node.append(node)
10531053

1054+
def render_math_block_label(self, token: SyntaxTreeNode) -> None:
1055+
content = token.content
1056+
label = token.info
1057+
node = nodes.math_block(content, content, nowrap=False, number=None)
1058+
self.add_line_and_source_path(node, token)
1059+
name = nodes.fully_normalize_name(label)
1060+
node["names"].append(name)
1061+
self.document.note_explicit_target(node, node)
1062+
self.current_node.append(node)
1063+
10541064
def render_amsmath(self, token: SyntaxTreeNode) -> None:
10551065
# note docutils does not currently support the nowrap attribute
10561066
# or equation numbering, so this is overridden in the sphinx renderer
@@ -1125,9 +1135,9 @@ def render_myst_role(self, token: SyntaxTreeNode) -> None:
11251135
)
11261136
inliner = MockInliner(self)
11271137
if role_func:
1128-
nodes, messages2 = role_func(name, rawsource, text, lineno, inliner)
1138+
_nodes, messages2 = role_func(name, rawsource, text, lineno, inliner)
11291139
# return nodes, messages + messages2
1130-
self.current_node += nodes
1140+
self.current_node += _nodes
11311141
else:
11321142
message = self.reporter.error(
11331143
f'Unknown interpreted text role "{name}".', line=lineno

tests/test_renderers/fixtures/docutil_syntax_extensions.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ $$foo$$
1010
$$
1111
a = 1
1212
$$
13+
14+
$$
15+
b = 2
16+
$$ (label)
1317
.
1418
<document source="<string>">
1519
<paragraph>
@@ -26,6 +30,9 @@ $$
2630
<math_block nowrap="False" number="True" xml:space="preserve">
2731

2832
a = 1
33+
<math_block ids="label" names="label" nowrap="False" number="True" xml:space="preserve">
34+
35+
b = 2
2936
.
3037

3138
[amsmath] --myst-enable-extensions=amsmath

0 commit comments

Comments
 (0)