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

Question how to modify ast and write back out as markdown #178

Closed
tvmaly opened this issue Mar 12, 2023 · 4 comments
Closed

Question how to modify ast and write back out as markdown #178

tvmaly opened this issue Mar 12, 2023 · 4 comments
Labels

Comments

@tvmaly
Copy link

tvmaly commented Mar 12, 2023

Could you add an example on how to take an AST of the markdown, modify it then write out the result to markdown?

@SomeoneSerge
Copy link

Related/duplicate of #4

@pbodnar
Copy link
Collaborator

pbodnar commented Mar 14, 2023

@SomeoneSerge is correct. I.e. right now, there is no MarkdownRenderer, but it is being worked on (namely in #162).

@tvmaly, I hope that this answers your question. :)

@pbodnar pbodnar closed this as completed Mar 14, 2023
@codekiln
Copy link

codekiln commented May 29, 2024

Note to others who wind up here; now that we have MarkdownRenderer class see its sub-section in https://github.com/miyuchina/mistletoe?tab=readme-ov-file#usage-from-python
... Maybe something like this...

with MarkdownRenderer(max_line_length=20) as renderer:
        print(renderer.render(mistletoe.Document(fin)))

@pbodnar
Copy link
Collaborator

pbodnar commented Jun 1, 2024

@codekiln, thanks for the update. Some more info then:

  1. The thing is one can use MarkdownRenderer as any other renderer in mistletoe. While of course, it has got special options like max_line_length which can be passed to the constructor (see its pydoc).

  2. Also note that there is this dedicated Markdown to Markdown parsing-and-rendering chapter available in the Developer's Guide, which shows how to modify the AST before rendering it back to markdown.

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

No branches or pull requests

4 participants