@ai-react-markdown/remark-mark-highlight
v1.0.0
Published
remark plugin for ==mark== highlight syntax — first-party successor to remark-mark-highlight, with dual ESM/CJS output.
Downloads
111
Maintainers
Readme
@ai-react-markdown/remark-mark-highlight
remark plugin for ==mark== highlight syntax: ==text== parses to an mdast mark node and renders as <mark>text</mark>.
First-party continuation of the unmaintained remark-mark-highlight, used internally by @ai-react-markdown/core's sealed highlight engine plugin — published standalone because it is useful outside this repo, and because the upstream's ESM-only exports map broke bare-Node CJS require() consumers.
Install
npm install @ai-react-markdown/remark-mark-highlightDual ESM/CJS build: both import and require work, types included for both.
Use
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import { remarkMarkHighlight } from '@ai-react-markdown/remark-mark-highlight';
const processor = unified().use(remarkParse).use(remarkMarkHighlight);
// '==hi==' → mdast: { type: 'mark', data: { hName: 'mark' }, children: [...] }
// → hast/HTML: <mark>hi</mark> (via data.hName — no custom handler needed)Serialization back to markdown (remark-stringify) is supported; == sequences round-trip.
Behavior contract
- Attention-style tokenizer (same family as GFM strikethrough): exactly two
=, standard flanking rules, nesting with emphasis/strong, escapes and code spans respected, spans may contain line endings. Interplay with other attention extensions (e.g. GFM strikethrough) follows micromark's shared attention machinery but is not part of the pinned corpus, which runs the plugin without GFM. - Byte-compatible with
[email protected]: a 50-case parity corpus (mdast with positions + hast), generated against the upstream before this package replaced it, runs in CI. Behavior changes would be a semver-major of this package.
Footguns
- Loading the plugin changes how
remark-stringifyescapes=. The serializer registers=as unsafe in phrasing content (so==spans survive round-trips), which escapes every phrasing=—let a = bserializes aslet a \= b. This matches the upstream's behavior and only affects stringify output, never parsing or rendering.
API
| Export | What |
| ------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| remarkMarkHighlight | The remark plugin (also aliased as remarkMark, the upstream's export name) |
| markHighlight() | The raw micromark extension |
| markHighlightFromMarkdown / markHighlightToMarkdown | The mdast from/to-markdown extensions |
| Mark (type) | The mdast node interface (type: 'mark'), registered in mdast's phrasing-content maps |
Versioning
This package versions independently of the @ai-react-markdown/core release train — core depends on it through a normal semver range.
License
MIT. Derived from the MIT-licensed remark-mark-highlight and micromark-extension-highlight-mark / mdast-util-highlight-mark; see LICENSE for attribution.
