markdown-it-py icon indicating copy to clipboard operation
markdown-it-py copied to clipboard

How to write my own renderer?

Open averms opened this issue 5 years ago • 2 comments

Is your feature request related to a problem? Please describe.

Is it simply a matter of copy pasting renderer.py and changing the functions? I imagine I would have to familiarize myself with the AST first.

I want to write a Vim help renderer and maybe also a Markdown renderer (#10).

averms avatar Sep 11 '20 06:09 averms

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:

welcome[bot] avatar Sep 11 '20 06:09 welcome[bot]

Hey @a-vrma yeh that would be cool thanks.

I guess the first place to look would be https://markdown-it-py.readthedocs.io/en/latest/using.html

In their words, markdown-it does not actually create an AST; it is a "token stream", i.e. it is not a tree, but a linear set of tokens like: [heading, open_paragraph, text, close_paragraph]

You can see what this looks like and how it works by going to https://markdown-it.github.io/ and clicking on the debug tab.

Apart from the built-in HTML render, the main implemented render is https://github.com/executablebooks/MyST-Parser/blob/master/myst_parser/docutils_renderer.py. This is relatively complex, but should give you some pointers. Note, for this renderer, I created the markdown_it.token.nest_tokens function, which I required to turn the token stream in to more of an AST tree, and may be useful for other renderers.

so yeh have a look at those, then come back with questions 😄

chrisjsewell avatar Sep 11 '20 17:09 chrisjsewell