-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add reStructuredText parsing functions to SphinxDirective
#12492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reStructuredText parsing functions to SphinxDirective
#12492
Conversation
cheers @AA-Turner love it ❤️ Haven't looked through in detail yet, but one request... can we link this to #12361, and have the new This would allow for e.g. MyST parser, or a different implementation of the rST parser to implement their own parsing logic |
Oh and also, I don't know if if it was in your planning, but we could also add an inline parse method for |
f430745
to
d66ac71
Compare
This isn't easily feasible, having had a quick go. It would be nice, but it in effect represents nested inline parsing.
I think this is automatic, as we use the current parser (by using the state machine directly). Very happy for someone to take this on in a follow-up though, if the current implementation is found wanting. A |
This assumes that the parser has a state machine, which is actually just an implementation detail of docutils, myst-parser has to go through absolutely hurdles to "pretend" it has one: https://github.com/executablebooks/MyST-Parser/blob/master/myst_parser/mocking.py
but yeh no problem I can do this |
@AA-Turner correct me if I'm wrong, but in this PR you have essentially changed all occurrences of But |
inliner: Inliner = state.inliner | ||
memo: Struct = state.memo | ||
parent: nodes.Element = state.parent | ||
return inliner.parse(text, lineno, memo, parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use state.inline_text(text, lineno)
here, as per the code you are replacing?
Its not a hard fix, but this definitely breaks the current implementation of myst-parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I didn't realise -- reverted to a simpler implementation in #12504.
A
See #12503, which restores the status quo ante. I do think in general that titles ought be allowed where possible, and that previously it may have more been a case of forgetting to allow them, but you make a good point that such a change should be made more deliberately. A |
where possible maybe, but I do want to emphasise that you cannot nest sections inside other nodes (like admonitions), without breaking the structure of the doctree: https://gist.github.com/chrisjsewell/0c5827add50074fef0937e2543e955b4 this is also the case in other text formats like: jgm/djot#213 what you could allow is headings that are not sections; and in-fact in myst-parser, rather than just omit them, they are actually changed to |
Given this, do you think that the new A |
In general, when the content contains no section headings, I think its absolutely fine, and this PR makes it that bit easier 👍 Its just when it comes to trying to nested parse section headings, thats when we really need to make sure people know what they are doing, because it can get quite nuanced; since sections are tightly-coupled to the structure of the document |
See sphinx-doc/sphinx#12492 The mypy warning only applies to `sphinx>=v7.4`, but the code is only executed for `sphinx<v6.2.0`.
As was colourfully espoused in #8039, it is harder than it ought to be to parse reStructuredText into nodes in a sphinx directive.
This PR adds three new functions:
SphinxDirective.parse_content_to_nodes()
, to parse the entirety ofSphinxDirective.content
SphinxDirective.parse_text_to_nodes()
, to parse a given stringSphinxDirective.parse_inline()
, to parse a text that is inline-onlyYet to finish is documentation and tests, but I am opening now for early feedback.
A