Open jessicah opened 1 year ago
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:
It seems like perhaps MyST-Parser's DocutilsRenderer
is the culprit, using a fixed list of renderers?
This might also explain what was going wrong in my WIP patch in https://github.com/executablebooks/MyST-Parser/issues/632
Ohh, I see, it's because the overridden render methods produces docutils AST nodes, correct? And the plugins produce HTML strings, which is why all the currently supported plugins have their equivalent render_xyz methods in the DocutilsRenderer
class. Still, an easy way to extend them would be useful... hmm.
Heya, yep indeed myst-parser intentionally does not expose markdown-it-py as the underlying markdown parser, it would not be maintainable to support such an API.
If you want to have a look at contributing your plugin to https://github.com/executablebooks/mdit-py-plugins, we can look to add it to myst-parser as an extension 😄 (there is already a node type for it, so should not be too difficult https://docutils.sourceforge.io/docs/ref/doctree.html#abbreviation)
@chrisjsewell ah, yeah, I was just at that docutils link, although not quite sure how to write the render_abbr
method in my python code.
I figured I can make a custom renderer by subclassing myst_parser.mdit_to_docutils.sphinx_.SphinxRenderer
, and calling create_md_parser(config, CustomRenderer)
:
class CustomRenderer(SphinxRenderer):
def render_abbr(self, token: SyntaxTreeNode) -> None:
print(token)
class CustomParser(MystParser):
def parse(self, inputstring: str, document: nodes.document) -> None:
config: MdParserConfig = document.settings.env.myst_config
# . . .
parser = create_md_parser(config, CustomRenderer)
# . . .
def setup(app):
from myst_parser.sphinx_ext.main import setup_sphinx
setup_sphinx(app, load_parser=False)
app.add_source_suffix(".md", "markdown")
app.add_source_parser(CustomParser)
I'm at least getting the print
outputing SyntaxTreeNode(abbr)
in my test, so it's just figuring out the final piece...
Some tips on what I should be producing in render_abbr
would be great, and I can make PRs for both :)
Yeh no worries, if you get the PR into executablebooks/mdit-py-plugins, I should be able to take care of the myst-parser side (it should be relatively straight forward)
@chrisjsewell any chance you can help me out with the myst-parser side as the plugin exists atm? I'd like to be able to start using in my own project ;-)
Describe the bug
context I've written a port of markdown-it-abbr to python, but when used with MyST-Parser, the replacement tokens are missing, due to an error of
WARNING: No render method for: abbr [myst.render]
.expectation In the rendered HTML, I expected the
<abbr>
HTML tag and content to be output.E.g. the following markdown:
should generate:
bug Instead, it generates:
I added
print(nodes)
at https://github.com/jessicah/mdit-py-abbr/blob/main/mdit_py_abbr/index.py#L157, and it showed up fine in console:So the token stream itself seems correct. Also, using markdown-it-py directly works correctly.
I did try adding a render method, but it had no effect. E.g.:
and
Reproduce the bug
I've created an example repo: https://github.com/jessicah/myst-demo
make [all]
runssphinx-build
, andmake test
runs the test file.List your environment
myst_parser: 0.18.1 sphinx: 5.3.0 docutils: 0.17.1 markdown_it: 1.1.0