executablebooks / MyST-NB

Parse and execute ipynb files in Sphinx
https://myst-nb.readthedocs.io
BSD 3-Clause "New" or "Revised" License
206 stars 82 forks source link

Support for custom extension #438

Open alibell opened 2 years ago

alibell commented 2 years ago

Context

The MyST-NB tool rely on MyST parser and support some pre-defined extensions. The markdown-it-py parser let it possible for user to create custom extensions, MyST inherit from this possibility using the use method.

In a current work, I developed some custom markdown extension for generating tables and figures for a data science report which rely on the Jupyter Book library.

My main issue is that I cannot declare my extension in Sphinx which rely on MyST-NB. I actually from with a kind of dirty fork of MyST-NB which load my custom extension directly in the parser.py file.

Proposal

Tasks and updates

No response

welcome[bot] commented 2 years 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:

chrisjsewell commented 2 years ago

Heya, I would be hesitant to tie myst-parser/myst-nb to markdown-it-py: the use of markdown-it-py is a design implementation that could change in the future and, as such, is not exposed to the user.

More generally, I would prefer to ultimately allow for the user just to provide the actual parser. The parser would be "loaded" with the configuration, then convert a source text to a JSON AST in a specified format (this is essentially what happens now). Then the myst-parser render would handle converting that JSON to the docutils/sphinx doctree.

Note, its normally more difficult than this though, to add a markdown-it extension, because there usually also has to be some logic added to themyst-parser renderer, to handle the new tokens created.