@vivliostyle/vfm
Version:
Custom Markdown syntax specialized in book authoring.
12 lines (11 loc) • 351 B
JavaScript
import findAndReplace from 'hast-util-find-and-replace';
import { h } from 'hastscript';
export function replace({ rules } = {}) {
if (!rules || rules.length == 0)
return;
const search = rules.map((rule) => [
rule.test,
(...result) => rule.match(result, h),
]);
return (tree) => findAndReplace(tree, search);
}