UNPKG

prosemirror-highlight

Version:

A ProseMirror plugin to highlight code blocks

26 lines (24 loc) 695 B
import { Decoration } from "prosemirror-view"; import { SugarHigh, tokenize } from "sugar-high"; //#region src/sugar-high.ts const types = SugarHigh.TokenTypes; function createParser() { return function parser({ content, pos }) { const decorations = []; const tokens = tokenize(content); let from = pos + 1; for (const [type, content] of tokens) { const to = from + content.length; const decoration = Decoration.inline(from, to, { class: `sh__token--${types[type]}`, style: `color: var(--sh-${types[type]})` }); decorations.push(decoration); from = to; } return decorations; }; } //#endregion export { createParser }; //# sourceMappingURL=sugar-high.js.map