Repository: executablebooks/MyST-Parser
Pull request #668 (2023-01-06 03:53:27)

👌 Add `render_math_block_label` for docutils

codecov[bot]: # [Codecov](https://codecov.io/gh/executablebooks/MyST-Parser/pull/668?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) Report
Base: **89.94**% // Head: **89.97**% // Increases project coverage by **`+0.03%`** :tada:
> Coverage data is based on head [(`ff3ea15`)](https://codecov.io/gh/executablebooks/MyST-Parser/pull/668?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) compared to base [(`2a5bd61`)](https://codecov.io/gh/executablebooks/MyST-Parser/commit/2a5bd6178e3ba578c94f34804ff852782cc9f85d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #668      +/-   ##
==========================================
+ Coverage   89.94%   89.97%   +0.03%     
==========================================
  Files          23       23              
  Lines        2396     2405       +9     
==========================================
+ Hits         2155     2164       +9     
  Misses        241      241              
```

| Flag | Coverage Δ | |
|---|---|---|
| pytests | `89.97% <100.00%> (+0.03%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/executablebooks/MyST-Parser/pull/668?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) | Coverage Δ | |
|---|---|---|
| [myst\_parser/mdit\_to\_docutils/base.py](https://codecov.io/gh/executablebooks/MyST-Parser/pull/668?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#diff-bXlzdF9wYXJzZXIvbWRpdF90b19kb2N1dGlscy9iYXNlLnB5) | `92.34% <100.00%> (+0.09%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/executablebooks/MyST-Parser/pull/668?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).


Patch:
diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py
index 4e4d412..ddeecdf 100644
--- a/myst_parser/mdit_to_docutils/base.py
+++ b/myst_parser/mdit_to_docutils/base.py
@@ -1051,6 +1051,16 @@ class DocutilsRenderer(RendererProtocol):
         self.add_line_and_source_path(node, token)
         self.current_node.append(node)
 
+    def render_math_block_label(self, token: SyntaxTreeNode) -> None:
+        content = token.content
+        label = token.info
+        node = nodes.math_block(content, content, nowrap=False, number=None)
+        self.add_line_and_source_path(node, token)
+        name = nodes.fully_normalize_name(label)
+        node["names"].append(name)
+        self.document.note_explicit_target(node, node)
+        self.current_node.append(node)
+
     def render_amsmath(self, token: SyntaxTreeNode) -> None:
         # note docutils does not currently support the nowrap attribute
         # or equation numbering, so this is overridden in the sphinx renderer
@@ -1125,9 +1135,9 @@ class DocutilsRenderer(RendererProtocol):
         )
         inliner = MockInliner(self)
         if role_func:
-            nodes, messages2 = role_func(name, rawsource, text, lineno, inliner)
+            _nodes, messages2 = role_func(name, rawsource, text, lineno, inliner)
             # return nodes, messages + messages2
-            self.current_node += nodes
+            self.current_node += _nodes
         else:
             message = self.reporter.error(
                 f'Unknown interpreted text role "{name}".', line=lineno


Test patch:
diff --git a/tests/test_renderers/fixtures/docutil_syntax_extensions.txt b/tests/test_renderers/fixtures/docutil_syntax_extensions.txt
index 5efcb68..2dc0d43 100644
--- a/tests/test_renderers/fixtures/docutil_syntax_extensions.txt
+++ b/tests/test_renderers/fixtures/docutil_syntax_extensions.txt
@@ -10,6 +10,10 @@ $$foo$$
 $$
 a = 1
 $$
+
+$$
+b = 2
+$$ (label)
 .
 <document source="<string>">
     <paragraph>
@@ -26,6 +30,9 @@ $$
     <math_block nowrap="False" number="True" xml:space="preserve">
 
         a = 1
+    <math_block ids="label" names="label" nowrap="False" number="True" xml:space="preserve">
+
+        b = 2
 .
 
 [amsmath] --myst-enable-extensions=amsmath