Repository navigation
🐛 FIX: Respect the parser option of the {include} directive - #1236
Open
Enesuygurs wants to merge 1 commit into
Open
Enesuygurs wants to merge 1 commit into
Enesuygurs wants to merge 1 commit into
Conversation
The option was accepted but ignored, so the file was always parsed as MyST. Parse it with the given parser into a new document, as the docutils include directive does. Fixes executablebooks#906
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #906
The MyST
{include}directive accepts theparseroption, since it reuses the option spec of the docutilsincludedirective, but then ignores it. The file is always rendered as MyST Markdown. For examplerenders
.. note:: hiinpart.rstas a plain paragraph rather than a note. A custom parser, like the one in the issue, is skipped the same way. An invalid parser name already produces amyst.directive_optionwarning, so only the valid case was broken.The cause is
MockIncludeDirective.runinmyst_parser/mocking.py. It handlesliteralandcodeand otherwise always does a MyST nested render. Nothing readsself.options["parser"].This PR adds a
parserbranch that does what docutils'Include.custom_parsedoes. The text goes into a new document, using the parser's default settings overlaid with the current document's settings. That document sharesids/nameids/nametypeswith the parent, so targets and duplicate ids are handled across the boundary. The parser's transforms are applied, the parse and transform messages are passed up to the parent, and the resulting children are returned. The implementation is local becausecustom_parseonly exists in newer docutils releases and we support>=0.20. I also listed the option in the include docs.Testing: I added an "Include with parser" case to
tests/test_renderers/fixtures/mock_include.md. It includes a small rST file with:parser: rstand expects anotenode. It fails on master, where the note is a paragraph, and passes with the change. I also checked a Sphinx build by hand. An rST file with a label, a:ref:and a note, included via:parser: rst, renders correctly, and[](#rst-label)in the including Markdown file resolves to it.:parser: myst_parser.sphinx_also works. The full test suite passes, and so doruff checkandruff format --check.