Skip to content
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

How to write my own renderer? #48

Closed
averms opened this issue Sep 11, 2020 · 2 comments
Closed

How to write my own renderer? #48

averms opened this issue Sep 11, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@averms
Copy link

averms commented Sep 11, 2020

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 averms added the documentation Improvements or additions to documentation label Sep 11, 2020
@welcome
Copy link

welcome bot commented Sep 11, 2020

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

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! 🎉

@chrisjsewell
Copy link
Member

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants