remarkjs / remark-rehype

plugin that turns markdown into HTML to support rehype
https://remark.js.org
MIT License
258 stars 18 forks source link

Can I keep HTML comments? #8

Closed davidtheclark closed 7 years ago

davidtheclark commented 7 years ago

I would like HTML comments from Markdown to remain in the tree ... but it seems that they're removed. If, however, I use remark-html to stringify the Markdown AST, then parse that with rehype-parse, the comments remain. It seems it would be more efficient if I could just use remark-rehype and keep the comments — but I can't figure out how to do that.

I've been jumping around between these module trying to figure this out and come up empty handed. Am I missing something?

wooorm commented 7 years ago

Hi! 👋 Good Q!

First of: if you want to do things with HTML (and you probably do), not just markdown, then remark-rehype is the good choice! Otherwise, remark-html with {allowDangerousHTML: true} is fine.

If you want to properly deal with HTML in markdown, you’ll need rehype-raw after remark-rehype. The example in its readme shows how to use these two together. (note: I just added that here too)

The downside of rehype-raw is that it contains a full-fledged HTML parser. If you can’t spare the resources for that (e.g., browser), you can pass {allowDangerousHTML: true} to remark-rehype and rehype-stringify respectively to get the comments to show up.

Does this help?

davidtheclark commented 7 years ago

@wooorm: This was exactly the advice I needed. Thanks!