How can I allow HTML-style <br> tags in markdown destined for React? #721
-
I'm currently using this: const schema = {
...githubSchema, // hast-util-sanitize/lib/github.json
attributes: {
...githubSchema.attributes,
code: [
// @ts-expect-error: this may exist some time in future
...(githubSchema.attributes.code ?? []),
"className",
],
},
clobberPrefix: "",
};
return unified()
.use(parse) // remark-parse
.use(gfm) // remark-gfm
.use(slug) // remark-slug
.use(remarkToReact, { // remark-react
sanitize: schema,
remarkReactComponents: {
// some custom components, no problems here
},
})
.processSync(data).result as React.ReactElement; If I'm reading the Github scheme correctly, it looks like But we noticed that Ending a line with a double space, however, is resulting in a line break. Is there something I can do to allow HTML-style line breaks too? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Short answer the flow is missing the option |
Beta Was this translation helpful? Give feedback.
Short answer the flow is missing the option
allowDangerousHtml
and pluginrehype-raw
, so HTML nodes aren't being passed through or parsed.What you are looking for sounds a lot like https://github.com/remarkjs/react-remark, specifically https://remarkjs.github.io/react-remark/?path=/story/remark-component--mixed-html-sanitized and https://github.com/remarkjs/react-remark/blob/e9a248b672a69cec4deef4c8235b40d53ac52970/stories/remark-hook.stories.tsx#L76-L79