👌 Improve generation of meta nodes by AA-Turner · Pull Request #1080 · executablebooks/MyST-Parser
This PR updates how HTML meta nodes are generated in MyST-Parser to ensure compatibility with Sphinx v9.
Changes Made
myst_parser/mdit_to_docutils/base.py
- Removed import:
from docutils.transforms.components import Filter - Changed return type of
html_meta_to_nodes():- Before:
list[nodes.pending | nodes.system_message] - After:
list[nodes.meta | nodes.system_message]
- Before:
- Simplified node generation: Instead of wrapping meta nodes in
nodes.pendingwith aFiltertransform, meta nodes are now directly returned
Test Fixtures Updated
tests/test_renderers/fixtures/docutil_syntax_elements.mdtests/test_renderers/fixtures/sphinx_syntax_elements.md
Expected output changed from <pending> nodes with internal transform details to direct <meta> nodes.
Assessment: ✅ Correct and Necessary
Why This Change is Needed
- Modern docutils/Sphinx behavior: In docutils 0.18+ (2021),
nodes.metabecame a standard node type that writers handle directly - Sphinx v9 compatibility: The old approach using
Filtertransform with pending nodes is deprecated/removed in newer Sphinx versions - Alignment with standards: This matches how Sphinx's own meta directive works in modern versions
Why It Works
- Writers that support HTML output process
nodes.metadirectly and render them as<meta>tags in the HTML<head>section - The change removes an unnecessary layer of indirection (pending nodes)
- Uses the standard docutils
nodes.metaapproach
Test Coverage
| Test Type | File | Coverage |
|---|---|---|
| Docutils renderer | tests/test_renderers/fixtures/docutil_syntax_elements.md |
"Front Matter HTML Meta" case |
| Sphinx renderer | tests/test_renderers/fixtures/sphinx_syntax_elements.md |
Same test case |
| CLI/config | tests/test_renderers/fixtures/myst-config.txt |
--myst-html-meta option |
| Sphinx HTML build | tests/test_sphinx/test_sphinx_builds.py::test_extended_syntaxes |
Meta nodes in HTML builds |
| Sphinx text build | tests/test_sphinx/test_sphinx_builds.py::test_extended_syntaxes_text |
Meta nodes with non-HTML builder |
Non-HTML Builder Coverage
The added test_extended_syntaxes_text test uses the text builder with the extended_syntaxes source directory, which has myst_html_meta configured.
This ensures that meta nodes don't cause issues for non-HTML builders—they simply don't render meta tags (as expected, since <meta> is an HTML-specific concept).