starboard-rich-editor
Version:
Rich text editor used in Starboard Notebook
52 lines • 1.67 kB
JavaScript
// @ts-nocheck
import { chainCommands, deleteSelection, selectNodeBackward, joinBackward } from "prosemirror-commands";
import { mathPlugin, mathBackspaceCmd, insertMathCmd, makeInlineMathInputRule, REGEX_INLINE_MATH_DOLLARS, } from "@benrbray/prosemirror-math";
import Node from "rich-markdown-editor/dist/nodes/Node";
import "katex/dist/katex.min.css";
import "@benrbray/prosemirror-math/style/math.css";
export default class Math extends Node {
get name() {
return "math_inline";
}
get schema() {
return {
group: "inline math",
content: "text*",
inline: true,
atom: true,
toDOM: () => ["math-inline", { class: "math-node", spellcheck: "false" }, 0],
parseDOM: [
{
tag: "math-inline",
},
],
};
}
commands({ type }) {
return () => insertMathCmd(type);
}
inputRules({ schema }) {
return [makeInlineMathInputRule(REGEX_INLINE_MATH_DOLLARS, schema.nodes.math_inline)];
}
keys({ type }) {
return {
"Mod-Space": insertMathCmd(type),
Backspace: chainCommands(deleteSelection, mathBackspaceCmd, joinBackward, selectNodeBackward),
};
}
get plugins() {
return [mathPlugin];
}
toMarkdown(state, node) {
state.write("$");
state.text(node.textContent);
state.write("$");
}
parseMarkdown() {
return {
block: "math_inline",
noCloseToken: true,
};
}
}
//# sourceMappingURL=Math.js.map