russross / blackfriday

Blackfriday: a markdown processor for Go
Other
5.41k stars 596 forks source link

How to render back to markdown? #670

Open jcorbin opened 4 years ago

jcorbin commented 4 years ago

Trying to write a program that's mostly an AST transformer, but I can't seem to find any way to turn a (v2) node back into markdown text ( short of writing my own markdown renderer that is, which I'd like to avoid? or at worst, contribute to the library, rather than maintain in my project? )

dmitshur commented 3 years ago

You might find https://github.com/jsternberg/markdownfmt to be relevant.

inliquid commented 3 years ago

Try https://github.com/JohannesKaufmann/html-to-markdown

suessflorian commented 2 years ago

Is there an answer for this? I'm also keen to render a blackfriday.Node back to markdown.

Vaelatern commented 1 year ago

I imported github.com/jsternberg/markdownfmt/markdown and used it as here: https://github.com/Vaelatern/mdbook-d2-go/blob/ace29af66b63df6f54abc66973104b49bb0d6c4f/main.go#L186-L192 to go from blackfriday's AST back to markdown

also pictured, an example of mutating an AST before returning it to markdown.