Skip to content

Commit 9362e44

Browse files
authored
👌 IMPROVE: Use correct renderer for state.inline_text (#466)
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.
1 parent b7ab7fc commit 9362e44

File tree

9 files changed

+70
-10
lines changed

9 files changed

+70
-10
lines changed

myst_parser/mocking.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ def inline_text(
181181
# so that the nested parse does not effect the current renderer,
182182
# but we use the same env, so that link references, etc
183183
# are added to the global parse.
184-
from myst_parser.docutils_renderer import DocutilsRenderer
185-
186-
nested_renderer = DocutilsRenderer(self._renderer.md)
184+
nested_renderer = self._renderer.__class__(self._renderer.md)
187185
options = {k: v for k, v in self._renderer.config.items()}
188186
options.update(
189187
{

tests/test_sphinx/sourcedirs/basic/content.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ abcd *abc* [google](https://www.google.com)
3434
3535
````
3636

37+
```{admonition} Title with [link](target2)
38+
Content
39+
```
40+
3741
(target2)=
3842

3943
```{figure} example.jpg

tests/test_sphinx/test_sphinx_builds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_basic(
6767
"date": "2/12/1985",
6868
"copyright": "MIT",
6969
"other": "Something else",
70-
"wordcount": {"minutes": 0, "words": 53},
70+
"wordcount": {"minutes": 0, "words": 57},
7171
}
7272

7373

tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx3.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
<warning>
3333
<paragraph>
3434
xyz
35+
<admonition classes="admonition-title-with-link-target2">
36+
<title>
37+
Title with
38+
<reference internal="True" refid="target2">
39+
<inline classes="std std-ref">
40+
link
41+
<paragraph>
42+
Content
3543
<target refid="target2">
3644
<figure align="default" ids="id1 target2" names="target2">
3745
<reference refuri="https://www.google.com">
@@ -140,7 +148,7 @@
140148
<paragraph>
141149
Special substitution references:
142150
<paragraph>
143-
53
151+
57
144152
words |
145153
0
146154
min read

tests/test_sphinx/test_sphinx_builds/test_basic.resolved.sphinx4.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
<warning>
3333
<paragraph>
3434
xyz
35+
<admonition classes="admonition-title-with-link-target2">
36+
<title>
37+
Title with
38+
<reference internal="True" refid="target2">
39+
<inline classes="std std-ref">
40+
link
41+
<paragraph>
42+
Content
3543
<target refid="target2">
3644
<figure ids="id1 target2" names="target2">
3745
<reference refuri="https://www.google.com">
@@ -140,7 +148,7 @@
140148
<paragraph>
141149
Special substitution references:
142150
<paragraph>
143-
53
151+
57
144152
words |
145153
0
146154
min read

tests/test_sphinx/test_sphinx_builds/test_basic.sphinx3.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ <h1>
5555
</p>
5656
</div>
5757
</div>
58+
<div class="admonition-title-with-link-target2 admonition">
59+
<p class="admonition-title">
60+
Title with
61+
<a class="reference internal" href="#target2">
62+
<span class="std std-ref">
63+
link
64+
</span>
65+
</a>
66+
</p>
67+
<p>
68+
Content
69+
</p>
70+
</div>
5871
<div class="figure align-default" id="id1">
5972
<span id="target2">
6073
</span>
@@ -229,7 +242,7 @@ <h1>
229242
Special substitution references:
230243
</p>
231244
<p>
232-
53 words | 0 min read
245+
57 words | 0 min read
233246
</p>
234247
</div>
235248
</div>

tests/test_sphinx/test_sphinx_builds/test_basic.sphinx3.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
<warning>
3333
<paragraph>
3434
xyz
35+
<admonition classes="admonition-title-with-link-target2">
36+
<title>
37+
Title with
38+
<pending_xref refdoc="content" refdomain="True" refexplicit="True" reftarget="target2" reftype="myst" refwarn="True">
39+
<inline classes="xref myst">
40+
link
41+
<paragraph>
42+
Content
3543
<target refid="target2">
3644
<figure align="default" ids="id1 target2" names="target2">
3745
<reference refuri="https://www.google.com">
@@ -141,7 +149,7 @@
141149
<paragraph>
142150
Special substitution references:
143151
<paragraph>
144-
53
152+
57
145153
words |
146154
0
147155
min read

tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ <h1>
5555
</p>
5656
</div>
5757
</div>
58+
<div class="admonition-title-with-link-target2 admonition">
59+
<p class="admonition-title">
60+
Title with
61+
<a class="reference internal" href="#target2">
62+
<span class="std std-ref">
63+
link
64+
</span>
65+
</a>
66+
</p>
67+
<p>
68+
Content
69+
</p>
70+
</div>
5871
<figure class="align-default" id="id1">
5972
<span id="target2">
6073
</span>
@@ -231,7 +244,7 @@ <h1>
231244
Special substitution references:
232245
</p>
233246
<p>
234-
53 words | 0 min read
247+
57 words | 0 min read
235248
</p>
236249
</section>
237250
</div>

tests/test_sphinx/test_sphinx_builds/test_basic.sphinx4.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
<warning>
3333
<paragraph>
3434
xyz
35+
<admonition classes="admonition-title-with-link-target2">
36+
<title>
37+
Title with
38+
<pending_xref refdoc="content" refdomain="True" refexplicit="True" reftarget="target2" reftype="myst" refwarn="True">
39+
<inline classes="xref myst">
40+
link
41+
<paragraph>
42+
Content
3543
<target refid="target2">
3644
<figure ids="id1 target2" names="target2">
3745
<reference refuri="https://www.google.com">
@@ -141,7 +149,7 @@
141149
<paragraph>
142150
Special substitution references:
143151
<paragraph>
144-
53
152+
57
145153
words |
146154
0
147155
min read

0 commit comments

Comments
 (0)