How prevent "rehype-sanitize" removing <section>
wrapper done by "remark-sectionize"
#133
-
How prevent "rehype-sanitize" removing import rehypeSanitize from "rehype-sanitize";
import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import remarkSectionize from "remark-sectionize";
const processor = unified()
.use(remarkParse) // parse markdown text to an AST
.use(remarkSectionize) // wraps stuff in sections (transforming the AST)
.use(remarkRehype) // convert the markdown AST to an HTML AST
.use(rehypeSanitize) // removes sections from remarkSectionize, when my goal is to keep them
.use(rehypeStringify)
const inputMarkdown = `
# Forest elephants
## Introduction
In this section, we discuss the lesser known forest elephants.
## Habitat
Forest elephants do not live in trees but among them.
`
processor.process(inputMarkdown) rehypeSanitize strips the sections, resulting in <h1>Forest elephants</h1>
<h2>Introduction</h2>
<p>In this section, we discuss the lesser known forest elephants.</p>
<h2>Habitat</h2>
<p>Forest elephants do not live in trees but among them.</p> When my goal is to keep them as so <section>
<h1>Forest elephants</h1>
<section>
<h2>Introduction</h2>
<p>In this section, we discuss the lesser known forest elephants.</p>
</section>
<section>
<h2>Habitat</h2>
<p>Forest elephants do not live in trees but among them.</p>
</section>
</section> |
Beta Was this translation helpful? Give feedback.
Answered by
aquaductape
Apr 21, 2023
Replies: 1 comment
-
Found the solution import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
rehypeSanitize({
...defaultSchema,
tagNames: [...defaultSchema.tagNames!, "section"],
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
aquaductape
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found the solution