Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 FIX: front-matter rendering with docutils (#477)
For the docutils base HTML writer, it is expected that `field_body` nodes contain block elements (e.g. `paragraph`) as children, rather than the `Text` node previously created by `DocutilsRenderer.dict_to_fm_field_list`.
- Loading branch information
1 parent
fb3e8e1
commit 6c44075
Showing
6 changed files
with
89 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
pytest_plugins = "sphinx.testing.fixtures" | ||
"""Top-level configuration for pytest.""" | ||
try: | ||
import sphinx # noqa: F401 | ||
except ImportError: | ||
pass | ||
else: | ||
# only use when Sphinx is installed, to allow testing myst-docutils | ||
pytest_plugins = "sphinx.testing.fixtures" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Test fixture files, using the ``DocutilsRenderer``. | ||
Note, the output AST is before any transforms are applied. | ||
""" | ||
from pathlib import Path | ||
|
||
import pytest | ||
from markdown_it.utils import read_fixture_file | ||
|
||
from myst_parser.docutils_renderer import DocutilsRenderer, make_document | ||
from myst_parser.main import MdParserConfig, create_md_parser | ||
|
||
FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"line,title,input,expected", | ||
read_fixture_file(FIXTURE_PATH.joinpath("docutil_roles.md")), | ||
ids=[ | ||
f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "docutil_roles.md") | ||
], | ||
) | ||
def test_docutils_roles(line, title, input, expected): | ||
"""Test output of docutils roles.""" | ||
parser = create_md_parser(MdParserConfig(), DocutilsRenderer) | ||
parser.options["document"] = document = make_document() | ||
parser.render(input) | ||
try: | ||
assert "\n".join( | ||
[ll.rstrip() for ll in document.pformat().splitlines()] | ||
) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) | ||
except AssertionError: | ||
print(document.pformat()) | ||
raise | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"line,title,input,expected", | ||
read_fixture_file(FIXTURE_PATH.joinpath("docutil_directives.md")), | ||
ids=[ | ||
f"{i[0]}-{i[1]}" | ||
for i in read_fixture_file(FIXTURE_PATH / "docutil_directives.md") | ||
], | ||
) | ||
def test_docutils_directives(line, title, input, expected): | ||
"""Test output of docutils directives.""" | ||
if title.startswith("SKIP"): # line-block directive not yet supported | ||
pytest.skip(title) | ||
parser = create_md_parser(MdParserConfig(), DocutilsRenderer) | ||
parser.options["document"] = document = make_document() | ||
parser.render(input) | ||
try: | ||
assert "\n".join( | ||
[ll.rstrip() for ll in document.pformat().splitlines()] | ||
) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) | ||
except AssertionError: | ||
print(document.pformat()) | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters