miyuchina/mistletoe

Question how to modify ast and write back out as markdown

Closed this issue · 4 comments

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

Related/duplicate of #4

@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. :)

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)))

@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.