shelving
Version:
Toolkit for using data in JavaScript.
15 lines (14 loc) • 874 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createMarkupRule } from "../MarkupRule.js";
import { createLineRegExp, LINE_CONTENT_REGEXP, LINE_SPACE_REGEXP } from "../util/regexp.js";
/**
* Headings are single line only (don't allow multiline).
* - `#` 1-6 hashes, then one or more spaces, then the title.
* - `#` must be the first character on the line.
* - Markdown's underline syntax is not supported (for simplification).
*/
export const HEADING_RULE = createMarkupRule(createLineRegExp(`(?<prefix>#{1,6})(?:${LINE_SPACE_REGEXP}+(?<heading>${LINE_CONTENT_REGEXP}))?`), (key, { prefix, heading = "" }, parser) => {
// The hash count picks the heading level; cast the dynamic tag to the known `h1`–`h6` set.
const Heading = `h${prefix.length}`;
return _jsx(Heading, { children: parser.parse(heading.trim(), "inline") }, key);
}, ["block"]);