Skip to content

Commit 21e1b43

Browse files
committed
Expose myst_substitions to RST
While this doesn't fix the fact that .. replace:: does not work within eval-rst, it does make it possible to perform substitutions within eval-rst using the same substitutions available to Jinja substitutions. Related: #680 Signed-off-by: Chance Zibolski <[email protected]>
1 parent 1038800 commit 21e1b43

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

myst_parser/mdit_to_docutils/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ def _render_finalise(self) -> None:
280280
substitution_node, f"wordcount-{key}"
281281
)
282282

283+
for key, value in self.md_config.substitutions.items():
284+
if value is None:
285+
continue
286+
287+
substitution_node = nodes.substitution_definition(
288+
str(value), nodes.Text(str(value))
289+
)
290+
substitution_node.source = self.document["source"]
291+
substitution_node["names"].append(key)
292+
self.document.note_substitution_def(substitution_node, key)
293+
283294
def nested_render_text(
284295
self,
285296
text: str,

tests/test_sphinx/sourcedirs/substitutions/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ This will not process the substitution
5252
{{ text_with_nest }}
5353
```
5454

55+
Test substitutions are processed within eval-rst
56+
57+
```{eval-rst}
58+
a |text| b
59+
```
60+
5561
Using env and filters:
5662

5763
{{ env.docname | upper }}

tests/test_sphinx/test_sphinx_builds/test_substitutions.html

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
</pre>
6363
</div>
6464
</div>
65+
<p>
66+
Test substitutions are processed within eval-rst
67+
</p>
68+
<p>
69+
a - text b
70+
</p>
6571
<p>
6672
Using env and filters:
6773
</p>

tests/test_sphinx/test_sphinx_builds/test_substitutions.xml

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
This will not process the substitution
4848
<literal_block language="python" xml:space="preserve">
4949
{{ text_with_nest }}
50+
<paragraph>
51+
Test substitutions are processed within eval-rst
52+
<paragraph>
53+
a
54+
- text
55+
b
5056
<paragraph>
5157
Using env and filters:
5258
<paragraph>

0 commit comments

Comments
 (0)