Skip to content

Commit 1df6b98

Browse files
committed
🐛 FIX: commonmark_only for directives
1 parent df14c91 commit 1df6b98

8 files changed

Lines changed: 86 additions & 4 deletions

File tree

myst_parser/docutils_renderer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ def render_fence(self, token):
363363
token.info = token.info.strip()
364364
language = token.info.split()[0] if token.info else ""
365365

366-
if language.startswith("{") and language.endswith("}"):
366+
if (
367+
not self.config.get("commonmark_only", False)
368+
and language.startswith("{")
369+
and language.endswith("}")
370+
):
367371
return self.render_directive(token)
368372

369373
if not language:

myst_parser/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def default_parser(config: MdParserConfig) -> MarkdownIt:
7272
raise ValueError("unknown renderer type: {0}".format(config.renderer))
7373

7474
if config.commonmark_only:
75-
return MarkdownIt("commonmark", renderer_cls=renderer_cls)
75+
md = MarkdownIt("commonmark", renderer_cls=renderer_cls)
76+
md.options.update({"commonmark_only": True})
77+
return md
7678

7779
md = (
7880
MarkdownIt("commonmark", renderer_cls=renderer_cls)
@@ -104,6 +106,7 @@ def default_parser(config: MdParserConfig) -> MarkdownIt:
104106

105107
md.options.update(
106108
{
109+
"commonmark_only": False,
107110
"enable_html_img": config.html_img_enable,
108111
"myst_url_schemes": config.url_schemes,
109112
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extensions = ["myst_parser"]
2+
exclude_patterns = ["_build"]
3+
myst_commonmark_only = True
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Test
2+
3+
```{note}
4+
hallo
5+
```
6+
7+
{a}`b`

tests/test_sphinx/test_sphinx_builds.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,28 @@ def test_footnotes(
129129
get_sphinx_app_doctree(app, docname="footnote_md", regress=True)
130130
finally:
131131
get_sphinx_app_output(app, filename="footnote_md.html", regress_html=True)
132+
133+
134+
@pytest.mark.sphinx(
135+
buildername="html",
136+
srcdir=os.path.join(SOURCE_DIR, "commonmark_only"),
137+
freshenv=True,
138+
)
139+
def test_commonmark_only(
140+
app,
141+
status,
142+
warning,
143+
get_sphinx_app_doctree,
144+
get_sphinx_app_output,
145+
remove_sphinx_builds,
146+
):
147+
"""test setting addition configuration values."""
148+
app.build()
149+
assert "build succeeded" in status.getvalue() # Build succeeded
150+
warnings = warning.getvalue().strip()
151+
assert "lexer name '{note}'" in warnings
152+
153+
try:
154+
get_sphinx_app_doctree(app, docname="index", regress=True)
155+
finally:
156+
get_sphinx_app_output(app, filename="index.html", regress_html=True)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<div class="documentwrapper">
2+
<div class="bodywrapper">
3+
<div class="body" role="main">
4+
<div class="section" id="test">
5+
<h1>
6+
Test
7+
<a class="headerlink" href="#test" title="Permalink to this headline">
8+
9+
</a>
10+
</h1>
11+
<div class="highlight-{note} notranslate">
12+
<div class="highlight">
13+
<pre><span></span>hallo
14+
</pre>
15+
</div>
16+
</div>
17+
<p>
18+
{a}
19+
<code class="docutils literal notranslate">
20+
<span class="pre">
21+
b
22+
</span>
23+
</code>
24+
</p>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<document source="index.md">
2+
<section ids="test" names="test">
3+
<title>
4+
Test
5+
<literal_block language="{note}" xml:space="preserve">
6+
hallo
7+
<paragraph>
8+
{a}
9+
<literal>
10+
b

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
[tox]
1414
envlist = py{36,37,38}-sphinx{2,3},docs
1515

16-
[testenv:py{36,37,38}-sphinx{2,3}]
16+
[testenv]
17+
# only recreate the environment when we use `tox -r`
1718
recreate = false
19+
20+
[testenv:py{36,37,38}-sphinx{2,3}]
1821
extras = testing
1922
deps =
2023
sphinx2: sphinx>=2,<3
2124
sphinx3: sphinx>=3,<4
2225
commands = pytest {posargs}
2326

2427
[testenv:docs]
25-
recreate = false
2628
extras = rtd
2729
whitelist_externals = rm
2830
commands =

0 commit comments

Comments
 (0)