miyuchina/mistletoe

question: how to render AST back to a markdown string

Closed this issue · 1 comments

Maybe a dumb question, but once I have the AST from a markdown file, e.g. with

from mistletoe import Document, ast_renderer

with open("test.md") as f:
    lines = f.readlines()
document = Document(lines)
output = ast_renderer.get_ast(document)

print(output)

Is there a way I can easily render the AST back to a markdown string again? Or would I need to write a custom markdown renderer to do the process in reverse.

My use case is that I'd like to make modifications to the AST and then write it back as a markdown file again.

Hi @sixhobbits, this is surely not a dumb question. :) Actually, this feature was questioned a while back in #4 which is still open and awaiting contributions. I have updated it with some fresh info, for the case you're interested...