-
Notifications
You must be signed in to change notification settings - Fork 12
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
♻️ REFACTOR: Move to markdown-it + mdformat renderer #18
Conversation
Note this PR also addresses some of the feedback in #11 |
Haha, yeah this is good stuff.
oh yeah this is a bit nasty, I think mdformat-myst probably does unexpected stuff here. This kind of conflicts the nesting assumptions of CommonMark and markdown-it so a case like this didn't even cross my mind. Does MyST syntax support nested directives btw (outside This is not the first time someone needs to render Markdown from tokens, so I think we may want to work on making something like build_mdit public to alleviate the various gotchas involved (regarding plugins and default conf options for example). |
Oh absolutely: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html#nesting-directives For myst-parser though, we do not implement this in the markdown parsing and so do not "encode" it in the markdown-it tokens; leaving it to the (docutils) directives to perform nested parses (see https://github.com/executablebooks/MyST-Parser/blob/649791694ba83c9b9295030c8cae9a6eee8fc767/myst_parser/mocking.py#L126). In this package, the default is indeed to just "wrap" all the directive text in It is also of note that in e.g. jupyter-book/mystmd#31, on the javascript end, we do not have the existing docutils directives, and so one would look to do everything within markdown-it TLDR: mdformat-myst may not fully solve the use case here, and we may need to look to "extend" it in some fashion to achieve this
sounds good to me 👍 |
Codecov Report
@@ Coverage Diff @@
## main #18 +/- ##
==========================================
+ Coverage 81.05% 83.86% +2.81%
==========================================
Files 8 10 +2
Lines 1341 1587 +246
==========================================
+ Hits 1087 1331 +244
- Misses 254 256 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Hey @hukkin I imagine you'll be interested in this (and hopefully want to get involved 😄)
So currently what this package does is convert RST source text -> docutils AST, via a modified RST parser that most importantly does not "resolve" all directives or roles, so that we can work out how to convert them back to MyST Markdown.
Then, in
rst_to_myst/renderer.py
, I walk through the AST and convert it "manually" to Markdown.What would obviously be good though, and what I have started in
rst_to_myst/markdownit.py
, is to convert the docutils AST -> Markdown-it tokens, then use mdformat/mdformat-myst to convert that to Markdown.Most of this should be quite straight-forward 🤞, but the only tricky part is directives that have nested parses, e.g.
is currently converted to AST (see
tests/fixtures/ast.txt
):and I don't believe mdformat/mdformat-myst has anything specific to handle this.