"Flattening" markdown with embedded HTML into pure markdown?
I need to be able to process markdown and replace embedded HTML content with the nearest markdown equivalent, e.g. replacing an HTML img element with a markdown embedded image link. The Copy Down library is great for HTML-to-MD conversion. However, I don't know how to use the Visitor pattern in CommonMark to replace an inline or block HTML element with markdown text. Can you please provide some guidance on how to do this?
You'd want to visit AST nodes for HTML in Markdown (HtmlBlock, HtmlInline), then parse their literal with an HTML parser and either insert the corresponding Markdown AST nodes to render later, or a custom AST node that renders raw Markdown later.
Does that help?
That's what I'm doing. (Although I'm unclear about how to splice it all together into a single Markdown node tree.) I'm suggesting that CommonMark support that conversion internally.