allowDangerousHTML doesn't work
See original GitHub issueIt looks like it’s not possible to get remark-react to render raw html, even when passing the allowDangerousHTML flag through to mdast-util-to-hast.
For example, attempting to add this unit test fails:
diff --git a/test/index.js b/test/index.js
index d6cb228..22d347e 100644
--- a/test/index.js
+++ b/test/index.js
@@ -121,6 +121,19 @@ versions.forEach(function(reactVersion) {
'passes toHast options to inner toHAST() function'
)
+ t.equal(
+ React.renderToStaticMarkup(
+ remark()
+ .use(reactRenderer, {
+ createElement: React.createElement,
+ toHast: {allowDangerousHTML: true}
+ })
+ .processSync('<strong>raw</strong> html').contents
+ ),
+ '<p><strong>raw</strong> html</p>',
+ 'renders raw html when specified'
+ )
+
fixtures.forEach(function(name) {
var base = path.join(root, name)
var input = fs.readFileSync(path.join(base, 'input.md'))
with the error:
not ok 6 renders raw html when specified
---
operator: equal
expected: '<p><strong>raw</strong> html</p>'
actual: '<p>raw html</p>'
Is there a different expected configuration to be able to support raw HTML inputs?
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
How to use custom components in react-markdown
Context: I have a Next.js site with Chakra UI. I have some user provided markdown content that is fetched from an external source...
Read more >mdast-util-to-hast - unified
Most utilities ignore raw nodes but two notable ones don't: hast-util-to-html also has an option allowDangerousHtml which will output the raw HTML.
Read more >@codepunkt/gatsby-remark-vscode - npm
A syntax highlighting plugin for Gatsby that uses VS Code's extensions, themes, and highlighting engine. Any language and theme VS Code supports ...
Read more >@mdx-js/mdx | MDX
Create a unified processor to compile MDX to JS. Has the same options as compile , but returns a configured processor . Note...
Read more >تويتر \ Titus على تويتر: "@vadimdemedes No not really; remark ...
I tried enabling `allowDangerousHTML` in every plugin, but didn't help I need to get more familiar with re* ecosystem, great work!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For those, who is looking for a way to use html tags in markdown with
remark-parse
, I leave this recipe here. Thanks to @ChristianMurphy for his suggestion. I’ve made just couple improvements:rehype-dom-parse
leads to error:document is not defined
. So I replace it withrehype-parse
.sanitize: false
You can try this snippet in console:
output:
@Hamms what I’ve been using is the
toHast
option https://github.com/remarkjs/remark-react#optionstohastWith: