Skip to content

Commit

Permalink
馃憣 IMPROVE: Use correct renderer for state.inline_text (#466)
Browse files Browse the repository at this point in the history
Previously `state.inline_text()` (used by some directives)
always parsed text with the `DocutilsRenderer`.
Now it will correctly use the `SphinxRenderer`,
when parsing with sphinx,
allowing for cross-document references to be handled.
  • Loading branch information
chrisjsewell committed Dec 16, 2021
1 parent b7ab7fc commit 9362e44
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 10 deletions.
4 changes: 1 addition & 3 deletions myst_parser/mocking.py
Expand Up @@ -181,9 +181,7 @@ def inline_text(
# so that the nested parse does not effect the current renderer,
# but we use the same env, so that link references, etc
# are added to the global parse.
from myst_parser.docutils_renderer import DocutilsRenderer

nested_renderer = DocutilsRenderer(self._renderer.md)
nested_renderer = self._renderer.__class__(self._renderer.md)
options = {k: v for k, v in self._renderer.config.items()}
options.update(
{
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sphinx/sourcedirs/basic/content.md
Expand Up @@ -34,6 +34,10 @@ abcd *abc* [google](https://www.google.com)
````

```{admonition} Title with [link](target2)
Content
```

(target2)=

```{figure} example.jpg
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinx/test_sphinx_builds.py
Expand Up @@ -67,7 +67,7 @@ def test_basic(
"date": "2/12/1985",
"copyright": "MIT",
"other": "Something else",
"wordcount": {"minutes": 0, "words": 53},
"wordcount": {"minutes": 0, "words": 57},
}


Expand Down
Expand Up @@ -32,6 +32,14 @@
<warning>
<paragraph>
xyz
<admonition classes="admonition-title-with-link-target2">
<title>
Title with
<reference internal="True" refid="target2">
<inline classes="std std-ref">
link
<paragraph>
Content
<target refid="target2">
<figure align="default" ids="id1 target2" names="target2">
<reference refuri="https://www.google.com">
Expand Down Expand Up @@ -140,7 +148,7 @@
<paragraph>
Special substitution references:
<paragraph>
53
57
words |
0
min read
Expand Up @@ -32,6 +32,14 @@
<warning>
<paragraph>
xyz
<admonition classes="admonition-title-with-link-target2">
<title>
Title with
<reference internal="True" refid="target2">
<inline classes="std std-ref">
link
<paragraph>
Content
<target refid="target2">
<figure ids="id1 target2" names="target2">
<reference refuri="https://www.google.com">
Expand Down Expand Up @@ -140,7 +148,7 @@
<paragraph>
Special substitution references:
<paragraph>
53
57
words |
0
min read
15 changes: 14 additions & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.sphinx3.html
Expand Up @@ -55,6 +55,19 @@ <h1>
</p>
</div>
</div>
<div class="admonition-title-with-link-target2 admonition">
<p class="admonition-title">
Title with
<a class="reference internal" href="#target2">
<span class="std std-ref">
link
</span>
</a>
</p>
<p>
Content
</p>
</div>
<div class="figure align-default" id="id1">
<span id="target2">
</span>
Expand Down Expand Up @@ -229,7 +242,7 @@ <h1>
Special substitution references:
</p>
<p>
53 words | 0 min read
57 words | 0 min read
</p>
</div>
</div>
Expand Down
10 changes: 9 additions & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.sphinx3.xml
Expand Up @@ -32,6 +32,14 @@
<warning>
<paragraph>
xyz
<admonition classes="admonition-title-with-link-target2">
<title>
Title with
<pending_xref refdoc="content" refdomain="True" refexplicit="True" reftarget="target2" reftype="myst" refwarn="True">
<inline classes="xref myst">
link
<paragraph>
Content
<target refid="target2">
<figure align="default" ids="id1 target2" names="target2">
<reference refuri="https://www.google.com">
Expand Down Expand Up @@ -141,7 +149,7 @@
<paragraph>
Special substitution references:
<paragraph>
53
57
words |
0
min read
15 changes: 14 additions & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.html
Expand Up @@ -55,6 +55,19 @@ <h1>
</p>
</div>
</div>
<div class="admonition-title-with-link-target2 admonition">
<p class="admonition-title">
Title with
<a class="reference internal" href="#target2">
<span class="std std-ref">
link
</span>
</a>
</p>
<p>
Content
</p>
</div>
<figure class="align-default" id="id1">
<span id="target2">
</span>
Expand Down Expand Up @@ -231,7 +244,7 @@ <h1>
Special substitution references:
</p>
<p>
53 words | 0 min read
57 words | 0 min read
</p>
</section>
</div>
Expand Down
10 changes: 9 additions & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml
Expand Up @@ -32,6 +32,14 @@
<warning>
<paragraph>
xyz
<admonition classes="admonition-title-with-link-target2">
<title>
Title with
<pending_xref refdoc="content" refdomain="True" refexplicit="True" reftarget="target2" reftype="myst" refwarn="True">
<inline classes="xref myst">
link
<paragraph>
Content
<target refid="target2">
<figure ids="id1 target2" names="target2">
<reference refuri="https://www.google.com">
Expand Down Expand Up @@ -141,7 +149,7 @@
<paragraph>
Special substitution references:
<paragraph>
53
57
words |
0
min read

0 comments on commit 9362e44

Please sign in to comment.