UNPKG

svem

Version:

Svelte in Markdown preprocessor

27 lines (26 loc) 612 B
import { visit } from "unist-util-visit"; const remarkAttributes = () => { return (tree) => { visit(tree, (node) => { node.attributes = getAttributes(node.meta ?? ""); }); }; }; const getAttributes = (meta) => { const parts = meta.match(/(\w+)(?:="([^"]*)")?/g) ?? []; const attributes = {}; parts.forEach((part) => { const [key, value = ""] = part.split("="); const match = value.match(/"([^"]+)"$/); if (match) { attributes[key] = match[1]; } else { attributes[key] = true; } }); return attributes; }; export { getAttributes, remarkAttributes };