-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Tiptap #27
Comments
I gave this a try, and found that a naive wrap of the inline math mostly works except for the arrow-key escaping, which always ends up on the side it entered. Not sure why it's remembering that? https://codesandbox.io/s/tiptap-math-04o0s?file=/src/components/HelloWorld.vue import { Node } from '@tiptap/core'
import {
makeBlockMathInputRule, makeInlineMathInputRule,
REGEX_INLINE_MATH_DOLLARS, REGEX_BLOCK_MATH_DOLLARS
} from "@benrbray/prosemirror-math";
import { mathPlugin, mathBackspaceCmd, insertMathCmd, mathSerializer } from "@benrbray/prosemirror-math";
export default Node.create({
name: 'math_inline',
group: "inline math",
content: "text*", // important!
inline: true, // important!
atom: true, // important!
parseHTML () {
return [{
tag: "math-inline" // important!
}]
},
renderHTML ({ HTMLAttributes }) {
return ["math-inline", { class: "math-node" }, 0]
},
addProseMirrorPlugins () {
return [
mathPlugin
]
},
addInputRules () {
return [
makeInlineMathInputRule(REGEX_INLINE_MATH_DOLLARS, this.type)
]
}
}) I love the package, by the way! I've hacked together something like this for myself, and it's not nearly as polished as this. |
Hey thanks! This is good to know, I wasn't expecting it to be so simple. It's pretty strange that it returns you to the same side you entered from -- I'm wondering if this is a quirk of how Tiptap manages NodeViews. If I'm remembering correctly, One way to test this hypothesis might be to see whether hooking up a much simpler NodeView to Tiptap (such as the footnote example) fails in the same way. |
Maybe this is a projection of a larger problem -- it seems that inserting text into an existing inline prosemirror-math NodeView generates a prosemirror error (despite successfully rendering the math for it afterward). This might take more work than my naive wrap sadly, and might resemble what one would do for the footnote you mentioned -- rewriting the NodeView logic on the Tiptap extension side. :(
|
Hi, One import mergeAttributes from '@tiptap/core/src/utilities/mergeAttributes' Thanks for sharing. I was looking for something like this for a while. Reached here by following Inline Math Integration for Tiptap1 | BrianHung/Math.css | gist.github.com. |
@xzackli would you please share your implementation/hack? i am in a need to implement that thing too. plus i want to implement other things as well... |
I finally got this to work with a few changes... import { Node, nodeInputRule, mergeAttributes } from "@tiptap/core";
import { mathPlugin } from "@benrbray/prosemirror-math";
export const regex = /(?:^|\s)((?:\$)((?:[^*]+))(?:\$))$/;
export const MathInline = Node.create({
name: "math_inline",
group: "inline math",
content: "text*", // important!
inline: true, // important!
atom: true, // important!
code: true,
parseHTML() {
return [
{
tag: "math-inline" // important!
}
];
},
renderHTML({ HTMLAttributes }) {
return ["math-inline", mergeAttributes({ class: "math-node" }, HTMLAttributes),0];
},
addProseMirrorPlugins() {
return [mathPlugin];
},
addInputRules() {
return [
nodeInputRule({find:regex, type:this.type})];
}
}); While this works, it does something strange. When I use |
It seems that |
Might be related to this change? ueberdosis/tiptap#1997 |
@cadars, so is there a solution? and also, I'm struggling to insert math_inline using commands. addCommands() {
return {
setMath: () => ({commands}) => {
// console.log("in math", x.can().setNode('math_inline'))
return commands.setNode('math_inline')
}
}
} The above doesn't work. any thoughts? |
Any updates about this issue? |
To make it compatible with the latest @tiptap input rules.
|
Leave the math block here as well in case anybody needed. The mathPlugin only need to be inserted once if both math-inline and math-display are created.
|
Does the keymap worked? |
Thanks for everyone in this thread for the examples! One hitch not yet working is the output of generateHtml, which only shows the raw TeX without being rendered by Katex. Has anyone gotten this working by any chance? (@wengtytt - you seem to have gotten the furthest) |
I'm glad to see some progress integrating with TipTap. I don't use TipTap myself, but I would happily accept PRs (or suggested improvements) targeted at making TipTap integration easier. |
Other than finding this thread, everything else was pretty straight-forward thanks to the examples by @wengtytt and others. One thing that could be improved are the required ProseMirror peer dependencies. TipTap has their own wrapper @tiptap/pm which is pretty much required if you're doing anything more than basic, meaning that these could be reused for The most convenient option imo would be to have the tiptap integration as a separate package which wraps FYI, TipTap has their own Mathematics extension as well, but it is behind a paywall and lacking in features / customisability compared to this package. |
Thanks for your help @wengtytt and others. 🙏 It's all working great except one thing: clicking on the rendered equations does not open them for editing, as it does in this example. Has anyone seen that issue? |
TipTap is a popular wysiwyg editor built on top of ProseMirror. I wonder if it would be possible to write an extension to TipTap based on
prosemirror-math
.The text was updated successfully, but these errors were encountered: