Remark plugin for processing MDX/Markdown by escaping HTML-sensitive characters in text nodes.
npm install gt-remarkA small Remark plugin to help safely stringify MDX/Markdown by escaping HTML-sensitive characters in text nodes, while leaving code, math, MDX expressions, and front-matter untouched.
- Escapes: {, }, &, <, >, ", ', _
- Ignores parents: code, inlineCode, mdxFlowExpression, mdxTextExpression, mdxjsEsm, yaml, toml, math, inlineMath
- Idempotent for & (does not double-escape existing entities)
``bash`
npm install gt-remark
`ts
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkStringify from 'remark-stringify';
import escapeHtmlInTextNodes from 'gt-remark';
const file = await unified()
.use(remarkParse)
.use(escapeHtmlInTextNodes)
.use(remarkStringify)
.process('Hello &
console.log(String(file));
`
- escapeHtmlInTextNodes`: Remark plugin with no options. Applies safe escaping to text nodes only.
FSL-1.1-ALv2