Skip to content

Commit

Permalink
Expose myst_substitions to RST
Browse files Browse the repository at this point in the history
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: executablebooks#680

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
  • Loading branch information
chancez committed Aug 22, 2024
1 parent 1038800 commit 21e1b43
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ def _render_finalise(self) -> None:
substitution_node, f"wordcount-{key}"
)

for key, value in self.md_config.substitutions.items():
if value is None:
continue

substitution_node = nodes.substitution_definition(
str(value), nodes.Text(str(value))
)
substitution_node.source = self.document["source"]
substitution_node["names"].append(key)
self.document.note_substitution_def(substitution_node, key)

def nested_render_text(
self,
text: str,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sphinx/sourcedirs/substitutions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ This will not process the substitution
{{ text_with_nest }}
```

Test substitutions are processed within eval-rst

```{eval-rst}
a |text| b
```

Using env and filters:

{{ env.docname | upper }}
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sphinx/test_sphinx_builds/test_substitutions.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
</pre>
</div>
</div>
<p>
Test substitutions are processed within eval-rst
</p>
<p>
a - text b
</p>
<p>
Using env and filters:
</p>
Expand Down
6 changes: 6 additions & 0 deletions tests/test_sphinx/test_sphinx_builds/test_substitutions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
This will not process the substitution
<literal_block language="python" xml:space="preserve">
{{ text_with_nest }}
<paragraph>
Test substitutions are processed within eval-rst
<paragraph>
a
- text
b
<paragraph>
Using env and filters:
<paragraph>
Expand Down

0 comments on commit 21e1b43

Please sign in to comment.