Closed
Description
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
rehype-format: ^4.0.0, rehype-raw: ^6.1.0, rehype-stringify: ^9.0.2, remark-gfm: ^2.0.0, remark-parse: ^10.0.0, remark-rehype: ^9.0.0, unified: ^10.1.0
Link to runnable example
No response
Steps to reproduce
Input Markdown
- [x] Some Text
Library Method
import rehypeFormat from 'rehype-format'
import rehypeRaw from 'rehype-raw'
import rehypeStringify from 'rehype-stringify'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import { unified } from 'unified'
async function render(
markdown: string
): Promise<string> {
const result = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeFormat)
.use(rehypeStringify, {
quoteSmart: true,
closeSelfClosing: true,
omitOptionalTags: true,
entities: { useShortestReferences: true }
})
.process(markdown)
return result.toString()
}
export default render
import fs from 'fs'
import { join } from 'path'
const docsDirectory = join(process.cwd(), 'docs')
export function getRawDocBySlug(slug: string): [string, string] {
const realSlug = slug.replace(/\.mdx$/, '')
const fullPath = join(docsDirectory, `${realSlug}.mdx`)
const fileContents = fs.readFileSync(fullPath, 'utf8')
return [realSlug, fileContents]
}
Usage
const DangerousMarkdown: FC<{ params: { slug: string } }> = ({ params }) => {
const [slug, content] = getRawDocBySlug(params.slug)
return <>
<h1>{slug}</h1>
<article dangerouslySetInnerHTML={{ __html: content }} />
</>
}
Expected behavior
<h1>foo</h1>
<article>
<ul class="contains-task-list">
<li class="task-list-item">
<input checked="" disabled="" type="checkbox"> Some Text
</li>
</ul>
</article>
Actual behavior
<h1>foo</h1>
<article>
<ul class="contains-task-list">
<li class="task-list-item">
<input checked="" disabled="" type="checkbox/"> Some Text
</li>
</ul>
</article>
Runtime
Node v16
Package manager
yarn v2
OS
Linux
Build and bundle tools
Next.js