Closed HT-Moh closed 3 years ago
Trying this
import { undo, redo } from 'prosemirror-history';
import { undoInputRule } from 'prosemirror-inputrules';
import {
makeInlineMathInputRule,
makeBlockMathInputRule,
REGEX_INLINE_MATH_DOLLARS_ESCAPED,
REGEX_BLOCK_MATH_DOLLARS,
mathPlugin,
mathBackspaceCmd,
mathSelectPlugin,
} from '@benrbray/prosemirror-math';
import { Keymap, chainCommands } from 'prosemirror-commands';
import { Extension } from 'rich-markdown-editor';
import { DOMOutputSpec } from 'prosemirror-model';
export default class ProsemirrorMath extends Extension {
// eslint-disable-next-line class-methods-use-this
get name() {
return 'prosemirror_math';
}
// eslint-disable-next-line class-methods-use-this
// get schema() {
// return {
// group: 'inline math',
// content: 'text*', // important!
// inline: true, // important!
// atom: true, // important!
// toDOM: () => ['prosemirror_math', { class: 'math-node' }, 0],
// parseDOM: [
// {
// tag: 'prosemirror_math', // important!
// },
// ],
// };
// }
// eslint-disable-next-line class-methods-use-this
get defaultOptions() {
return {
node: 'paragraph',
notAfter: ['paragraph', 'heading'],
};
}
// eslint-disable-next-line class-methods-use-this
keys() {
return {
'Mod-z': undo,
'Mod-y': redo,
'Shift-Mod-z': redo,
Backspace: chainCommands(mathBackspaceCmd, undoInputRule),
};
}
// eslint-disable-next-line class-methods-use-this
get plugins() {
return [mathPlugin, mathSelectPlugin];
}
// eslint-disable-next-line class-methods-use-this
get inputRules() {
return [
makeInlineMathInputRule(
REGEX_INLINE_MATH_DOLLARS_ESCAPED,
(() => {
const type = this.editor.schema.nodes[this.name];
if (type === undefined) {
throw new Error(
`error retrieving node type for extension ${this.name}`
);
}
return type;
})()
),
];
}
}
`
I assume I need to add a node to the schema but I am not sure how.
_Originally posted by @HT-Moh in https://github.com/outline/rich-markdown-editor/discussions/498#discussioncomment-1025809_
Hi, there is already a PR for this functionality – you can use it as a base or complete the PR if you like, I haven't had time to work on it:
Hi, thanks I went through PR, but I am wondering if there a way to attach extension to the Editor without changing the library? What it's the use of the extension prop?,can be used to add this plugin?
Yes, you could do the same thing but pass the extension into the editor with the extensions prop instead of hardcoding it in index.tsx
Going to close this issue as it's already covered by this one: https://github.com/outline/outline/issues/1038 – feel free to reply though
Yes, you could do the same thing but pass the extension into the editor with the extensions prop instead of hardcoding it in
index.tsx
Going to close this issue as it's already covered by this one: outline/outline#1038 – feel free to reply though
Yes, on the editor I am passing ProsemirrorMath to the extensions props already, but actually my problem is the node.
How do I create a node and add it to the class ProsemirrorMath
?
Ah, I understand now. There isn't currently a way to register new markdown parsers from outside of the library – you'd have to either:
Discussed in https://github.com/outline/rich-markdown-editor/discussions/498