prosemirror-lezer
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

prosemirror-lezer

Warning This is an experimental plugin forked from b-kelly/prosemirror-highlightjs. In its current state, this should not be used in production, as I'm not sure if I'll be maintaining this moving forward.

Usage

import { parser } from "@lezer/markdown";
import { highlightPlugin } from "prosemirror-lezer";

// parsers are keyed by language or optionally `*` as a fallback
const parsers = {
    "markdown": parser,
};

let state = new EditorView(..., {
  state: EditorState.create({
    doc: ...,
    plugins: [highlightPlugin(parsers)],
  })
});

Or import just the decoration parser and write your own plugin:

import { getHighlightDecorations } from "prosemirror-lezer";

let plugin = new Plugin({
    state: {
        init(config, instance) {
            let content = getHighlightDecorations(
                instance.doc,
                parsers,
                blockTypes,
                languageExtractor
            );
            return DecorationSet.create(instance.doc, content);
        },
        apply(tr, set) {
            if (!tr.docChanged) {
                return set.map(tr.mapping, tr.doc);
            }

            let content = getHighlightDecorations(
                tr.doc,
                parsers,
                blockTypes,
                languageExtractor
            );
            return DecorationSet.create(tr.doc, content);
        },
    },
    props: {
        decorations(state) {
            return this.getState(state);
        },
    },
});

Readme

Keywords

Package Sidebar

Install

npm i prosemirror-lezer

Weekly Downloads

1,198

Version

0.0.5

License

MIT

Unpacked Size

31.1 kB

Total Files

13

Last publish

Collaborators

  • benkelly