-
-
Notifications
You must be signed in to change notification settings - Fork 856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid HTML syntax together with rehype-raw
causes crash
#833
Comments
Can also be reproduced by pasting that code at https://remarkjs.github.io/react-markdown/ |
Can also be reproduced with just the utilities: import assert from 'node:assert/strict'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toHast} from 'mdast-util-to-hast'
import {raw} from 'hast-util-raw'
import {toHtml} from 'hast-util-to-html'
const document = `
Note how this markdown has invalid HTML below. The closing "summary" tag is missing a closing angle bracket.
<details>
<summary>Complete logs</summary
</details>
`
const mdast = fromMarkdown(document)
const hast = toHast(mdast, {allowDangerousHtml: true})
assert(hast.type === 'root')
const reformatted = raw(hast)
console.log(reformatted)
console.log(toHtml(reformatted))
|
Even smaller, and making the exception disappear: /**
* @typedef {import('hast').Root} Root
*/
import {raw} from 'hast-util-raw'
import {toHtml} from 'hast-util-to-html'
/** @type {Root} */
const hast = {
type: 'root',
children: [
{type: 'raw', value: '<details>\n<summary>Complete logs</summary'},
{type: 'text', value: '\n'},
{type: 'raw', value: '</details>'}
]
}
const reformatted = raw(hast)
console.log(reformatted)
console.log(toHtml(reformatted)) Removing the We intentionally do want to support a |
This comment has been minimized.
This comment has been minimized.
released! |
Awesome thanks. Confirmed that |
Initial checklist
Affected packages and versions
react-markdown@9.0.1 + rehype-raw@7.0.0
Link to runnable example
https://stackblitz.com/edit/github-nbnqac?file=src%2Fapp.tsx
Steps to reproduce
When
react-markdown
is used together withrehype-raw
and invalid HTML is provided inside the markdown content, it causes a crash with:See Stackblitz link for a repro, or use this code:
Expected behavior
No crash. Ideally
rehype-raw
could be smart enough to auto-close the tag (like GitHub's markdown editor does), but if that's too difficult, simply not rendering that element is fine too.Actual behavior
Code crashes with the error above.
Runtime
Node v17
Package manager
npm 8
OS
Linux
Build and bundle tools
Webpack
The text was updated successfully, but these errors were encountered: