UNPKG

prosemirror-highlight

Version:

A ProseMirror plugin to highlight code blocks

20 lines (18 loc) 604 B
import { Decoration } from "prosemirror-view"; import { highlightTree } from "@lezer/highlight"; //#region src/lezer.ts function createParser({ parse, highlighter }) { return function lezerParser(options) { const tree = parse(options); if (!tree) return []; const decorations = []; const offset = options.pos + 1; highlightTree(tree, highlighter, (from, to, classes) => { if (classes && from < to) decorations.push(Decoration.inline(offset + from, offset + to, { class: classes })); }); return decorations; }; } //#endregion export { createParser }; //# sourceMappingURL=lezer.js.map