Handling HTML in Markdown using rehype-dom
#202
Unanswered
filipsobol
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In CKEditor 5 we are considering rewriting our
markdown-gfmfeature to use the unifiedjs ecosystem. Since the editor runs in the browser, we want to use packages that rely on native DOM APIs instead of external HTML parsers to reduce the bundle size. However, this becomes difficult when I need to add support for HTML inside Markdown because all the out-of-the-box solutions that support this rely onparse5.Let's use the following Markdown as an example:
Now let's use
rehype-dom-stringifyto stringify this:In return, I get the following HTML:
There are two ways to fix this using OOTB solutions:
rehype-stringifywithallowDangerousHtml: trueoption (instead ofrehype-dom-stringifywhich does not support this option).rehype-rawbeforerehypeStringify.Both of them will produce the desired output:
Unfortunately, both of these also rely on
parse5, which we want to avoid. Below is a solution that uses native browser APIs. However, I'd like to get your opinion on the best approach. Is there an existing solution I may have missed? Does the solution below have any obvious issues?Beta Was this translation helpful? Give feedback.
All reactions