Skip to content

Commit

Permalink
⬆️ UPGRADE: docutils 0.19 support (#611)
Browse files Browse the repository at this point in the history
This PR allows docutils 0.19 to be used with myst-parser.
See: https://docutils.sourceforge.io/RELEASE-NOTES.html#release-0-19-2022-07-05.
Note though, it does not fix a number of `DeprecationWarning` that arise from using docutils 0.19, which will be addressed at a later date.
  • Loading branch information
chrisjsewell authored Aug 15, 2022
1 parent 363b853 commit 3105807
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
strategy:
fail-fast: false
matrix:
docutils-version: ["0.16", "0.17", "0.18"]
docutils-version: ["0.17", "0.18", "0.19"]

steps:
- name: Checkout source
Expand Down
9 changes: 7 additions & 2 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,16 @@ def html_meta_to_nodes(
return []

try:
# if sphinx available
from sphinx.addnodes import meta as meta_cls
except ImportError:
from docutils.parsers.rst.directives.html import MetaBody
try:
# docutils >= 0.19
meta_cls = nodes.meta # type: ignore
except AttributeError:
from docutils.parsers.rst.directives.html import MetaBody

meta_cls = MetaBody.meta # type: ignore
meta_cls = MetaBody.meta # type: ignore

output = []

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ keywords = [
]
requires-python = ">=3.7"
dependencies = [
"docutils>=0.15,<0.19",
"docutils>=0.15,<0.20",
"jinja2", # required for substitutions, but let sphinx choose version
"markdown-it-py>=1.0.0,<3.0.0",
"mdit-py-plugins~=0.3.0",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_renderers/fixtures/docutil_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
.
<document source="notset">
<paragraph>
<reference refuri="http://www.python.org/dev/peps/pep-0000">
<reference refuri="https://peps.python.org/pep-0000">
PEP 0
.

Expand All @@ -104,7 +104,7 @@
.
<document source="notset">
<paragraph>
<reference refuri="http://tools.ietf.org/html/rfc1.html">
<reference refuri="https://tools.ietf.org/html/rfc1.html">
RFC 1
.

Expand Down
13 changes: 12 additions & 1 deletion tests/test_renderers/test_fixtures_docutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ def _apply_transforms(self):
parser=Parser(),
)

file_params.assert_expected(doctree.pformat(), rstrip_lines=True)
ptree = doctree.pformat()
# docutils >=0.19 changes:
ptree = ptree.replace(
'refuri="http://tools.ietf.org/html/rfc1.html"',
'refuri="https://tools.ietf.org/html/rfc1.html"',
)
ptree = ptree.replace(
'refuri="http://www.python.org/dev/peps/pep-0000"',
'refuri="https://peps.python.org/pep-0000"',
)

file_params.assert_expected(ptree, rstrip_lines=True)


@pytest.mark.param_file(FIXTURE_PATH / "docutil_directives.md")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sphinx/test_sphinx_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def test_include_from_rst(
)


@pytest.mark.skipif(
__version_info__ < VersionInfo(0, 19, 0, "final", 0, True),
reason="Footnote HTML changed in docutils 0.19",
)
@pytest.mark.sphinx(
buildername="html", srcdir=os.path.join(SOURCE_DIR, "footnotes"), freshenv=True
)
Expand Down
204 changes: 103 additions & 101 deletions tests/test_sphinx/test_sphinx_builds/test_footnotes.sphinx5.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,113 +97,115 @@ <h1>
</div>
</blockquote>
<hr class="footnotes docutils"/>
<aside class="footnote brackets" id="c" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id1" role="doc-backlink">
1
</a>
<span class="fn-bracket">
]
</span>
</span>
<p>
a footnote referenced first
</p>
</aside>
<aside class="footnote brackets" id="d" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id2" role="doc-backlink">
2
</a>
<span class="fn-bracket">
]
</span>
</span>
<p>
a footnote referenced in a directive
</p>
</aside>
<aside class="footnote brackets" id="a" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id3" role="doc-backlink">
3
</a>
<span class="fn-bracket">
]
</span>
</span>
<p>
some footnote
<em>
text
</em>
</p>
</aside>
<aside class="footnote brackets" id="b" role="note">
<span class="label">
<span class="fn-bracket">
[
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="c" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id1" role="doc-backlink">
1
</a>
<span class="fn-bracket">
]
</span>
</span>
<a href="#id4" role="doc-backlink">
4
</a>
<span class="fn-bracket">
]
<p>
a footnote referenced first
</p>
</aside>
<aside class="footnote brackets" id="d" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id2" role="doc-backlink">
2
</a>
<span class="fn-bracket">
]
</span>
</span>
</span>
<p>
a footnote before its reference
</p>
</aside>
<aside class="footnote brackets" id="id8" role="note">
<span class="label">
<span class="fn-bracket">
[
<p>
a footnote referenced in a directive
</p>
</aside>
<aside class="footnote brackets" id="a" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id3" role="doc-backlink">
3
</a>
<span class="fn-bracket">
]
</span>
</span>
123
<span class="fn-bracket">
]
<p>
some footnote
<em>
text
</em>
</p>
</aside>
<aside class="footnote brackets" id="b" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id4" role="doc-backlink">
4
</a>
<span class="fn-bracket">
]
</span>
</span>
</span>
<span class="backrefs">
(
<a href="#id5" role="doc-backlink">
1
</a>
,
<a href="#id6" role="doc-backlink">
2
</a>
)
</span>
<p>
multiple references footnote
</p>
</aside>
<aside class="footnote brackets" id="e" role="note">
<span class="label">
<span class="fn-bracket">
[
<p>
a footnote before its reference
</p>
</aside>
<aside class="footnote brackets" id="id8" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
123
<span class="fn-bracket">
]
</span>
</span>
<a href="#id7" role="doc-backlink">
5
</a>
<span class="fn-bracket">
]
<span class="backrefs">
(
<a href="#id5" role="doc-backlink">
1
</a>
,
<a href="#id6" role="doc-backlink">
2
</a>
)
</span>
<p>
multiple references footnote
</p>
</aside>
<aside class="footnote brackets" id="e" role="note">
<span class="label">
<span class="fn-bracket">
[
</span>
<a href="#id7" role="doc-backlink">
5
</a>
<span class="fn-bracket">
]
</span>
</span>
</span>
<p>
footnote definition in a block element
</p>
<p>
footnote definition in a block element
</p>
</aside>
</aside>
</section>
</div>
Expand Down

0 comments on commit 3105807

Please sign in to comment.