Parse markdown and serialize it back to markdown

I've tried installing the comrak crate, which does support parsing Markdown, modifying the nodes and translating them back to CommonMark (which was not exactly what I was looking for, since I wanted Markdown back and not the CommonMark spec.), however comrak seems to be stuck when rustc compiles it, so I gave up on comrak.

I know markdown-it will allow me to parse and modify the nodes, but it doesn't render back to Markdown as far as I know.

I need to modify the nodes basically to fix image links. Also nice to convert HTML tags to Markdown equivalent syntax when possible.

Any ideas of another crate?

The markdown crate can serialize the AST back to markdown.

1 Like

But images are represented in that? Block::Raw?

Ah, I see... Span::Image

I've done this in the past with pulldown-cmark and pulldown-cmark-to-cmark. I find it quite easy for making tweaks to the Markdown, here is an actual code example converting relative links in the Markdown.

1 Like