-
Notifications
You must be signed in to change notification settings - Fork 71
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
Support: Markdown to Markdown (round trip) #164
Comments
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗 |
I think this does what you want. Note that I never ran this so expect some debugging. This also doesn't include support for extra syntax like the from markdown_it import MarkdownIt
from mdformat.renderer import MDRenderer
your_markdown = "# Heading\nParagraph\n"
mdit = MarkdownIt()
env = {}
tokens = mdit.parse(your_markdown, env)
tokens_parts = ... # Split the token stream here
for part in tokens_parts:
rendered_part = MDRenderer().render(part, mdit.options, env)
print(rendered_part) |
Thanks for the assist! This is what ended up working:
I had to split the tokens manually, but there must be a way to process it so that I can split it algorithmically (like Will keep looking through the docs and code to find how to do this. P.S. If this is a useful example, I'm happy to also include this as part of the documentation. |
Managed to brute-force it like this:
Output:
|
I have the same issue with this, Will be good if there is an document can describe how to do this |
I've been looking for a markdown parser and I think I've found what I'm looking for in
markdown-it-py
. Being a big fan of Jupyterbook, I figure it's best to stay in the family. Thanks for creating this!I'm having some difficulty trying to do something very specific - I have a feeling this is related to an open issue (#10).
Here is my source markdown file (with a YAML header):
I would like to parse this markdown file and create four different strings:
YAML Header
Heading
Block 1 and 2
and
Is this possible with
markdown-it-py
? I don't want to convert/render it to html and then convert it to markdown, that seems like an extra unnecessary step.I've created a minimal working example in a Jupyter Notebook here: https://github.com/firasm/mwe_md-it-py/blob/main/example.ipynb.
The crux of my issue is that I have the
tokens
, and I can create aSyntaxTreeNode
, but I eventually need to turn those into objects that I could export. Even if I can't read in the YAML header, parsing the rest of the markdown would still be useful.The text was updated successfully, but these errors were encountered: