Commit fcf78ca
👌 Improve generation of meta nodes (#1080)
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`
1. **Removed import**: `from docutils.transforms.components import
Filter`
2. **Changed return type** of `html_meta_to_nodes()`:
- Before: `list[nodes.pending | nodes.system_message]`
- After: `list[nodes.meta | nodes.system_message]`
3. **Simplified node generation**: Instead of wrapping meta nodes in
`nodes.pending` with a `Filter` transform, meta nodes are now directly
returned
### Test Fixtures Updated
- `tests/test_renderers/fixtures/docutil_syntax_elements.md`
- `tests/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
1. **Modern docutils/Sphinx behavior**: In docutils 0.18+ (2021),
`nodes.meta` became a standard node type that writers handle directly
2. **Sphinx v9 compatibility**: The old approach using `Filter`
transform with pending nodes is deprecated/removed in newer Sphinx
versions
3. **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.meta` directly 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.meta` approach
## 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).
---------
Co-authored-by: Chris Sewell <chrisj_sewell@hotmail.com>1 parent e0fc7a3 commit fcf78ca
File tree
5 files changed
+103
-74
lines changed- myst_parser/mdit_to_docutils
- tests
- test_renderers/fixtures
- test_sphinx
- test_sphinx_builds
5 files changed
+103
-74
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
1883 | 1882 | | |
1884 | 1883 | | |
1885 | 1884 | | |
1886 | | - | |
| 1885 | + | |
1887 | 1886 | | |
1888 | 1887 | | |
1889 | 1888 | | |
| |||
1917 | 1916 | | |
1918 | 1917 | | |
1919 | 1918 | | |
1920 | | - | |
1921 | | - | |
1922 | | - | |
1923 | | - | |
1924 | | - | |
1925 | | - | |
1926 | | - | |
1927 | | - | |
| 1919 | + | |
| 1920 | + | |
1928 | 1921 | | |
1929 | 1922 | | |
1930 | 1923 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
707 | 679 | | |
708 | 680 | | |
709 | 681 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
709 | 681 | | |
710 | 682 | | |
711 | 683 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
245 | 274 | | |
246 | 275 | | |
247 | 276 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
0 commit comments