-
Notifications
You must be signed in to change notification settings - Fork 11
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
Pasting rich HTML content mixed with LaTeX #7
Comments
Is |
I think this might be an issue with the pasting rules regex, but not sure yet. Could you include the latex string you are having the issue with and your browser version? I tried pasting |
Ah I think my version had an extra Anyway, is there a way to allow editing without requiring a backspace? Like it the equation was focused? Tiptap's Mathematics one does it, any reason why this doesn't? |
@aarkue Can you try pasting stuff from https://tiptap.dev/docs/editor/api/extensions/mathematics#katex-options example and see if it renders automatically? I tried and it doesn't. Screen.Recording.2024-06-08.at.14.25.01.mov |
To be honest, I am not really a fan of the jump from rendered LaTeX to the source LaTeX expression when the cursor navigates to the rendered LaTeX. Additionally, the implementation of this plugin right now is fairly simple and only uses the exposed TipTap extensions API (without reaching in addProseMirrorPlugins etc.). However, I think adding some functionality to optionally enable this (or even just allowing users to edit the expression after clicking on it) might be on the roadmap in the future. 👍 |
Thanks for the reproduction example! I will investigate how we could handle converting LaTeX pasted inside HTML. |
Some progress: The TipTap APIs (PasteRules and InputRules) do not trigger when pasting rich HTML content mixes with (plain text) LaTeX. Using parseHTML is also not applicable, as the example copied HTML (i.e., from the official TipTap mathematics extension) does not wrap the LaTeX in any special HTML tags. Overall, this means that handling LaTeX inside pasted HTML is not possible without reaching for the ProseMirror API surface. This might be addressable in the future, but for now, it seems like not worth pursuing further. Pasting as plain text (Cmd/Ctrl+Shift+v) seems like a good enough workaround for the moment. |
Fair, for now I've gone ahead with the package from Tiptap, but it suffers from re-painting and re-rendering causing the app to slow down when there's a lot, while your package didn't. Would you be okay keeping this issue open, till you either find a fix or deem it not worth fixing? |
Yes definitively, we can keep this issue open for tracking! Cheers |
@aarkue @rajatkulkarni95 hi guys,I also encountered the same problem. I had to delete the ending QQ2024611-17122.mp4 |
@xiangshu233 hi, Instead, try inserting the latex formula as content element (either JSON or HTML) using
Let me know if that works for you! |
@aarkue Many thanks for the prompt reply. click: (latex) => {
editor?.chain()
.insertContent(`<span data-type="inlineMath" data-latex="${latex}"></span>`)
.focus()
.run()
}, But I am still curious about what causes the deletion The problem is that the formula can only be rendered correctly if QQ2024611-18815.mp4 |
@xiangshu233 No problem! I would actually recommend inserting via JSON instead of HTML to be more robust for future updates, but both should work fine for now. Regarding the pasting issue: Pasting
Cheers :) |
@aarkue Thank you, I know why copying from rich text doesn't work
This is the result I got in addition, the official math extension can directly identify HTML tags such as |
@xiangshu233 Ahh okay, thanks for confirming! This is exactly the thing this original issue is about. Fixing this will probably require using the ProseMirror API to handle such paste event scenarios (i.e. pasting HTML content with LaTeX inside I will keep you updated once I get further to fixing this, but right now it is not really a priority. Cheers! |
@aarkue Hello, sorry to bother you. I am currently using this plugin. editor?.chain().insertContent(`<span data-type="inlineMath" data-latex="\\tan {\\theta }=\\frac {\\sin {\\theta }} {\\cos {\\theta }}"></span>`).focus().run() I have been troubleshooting for a long time but can't find the problem😂. Can you help me? QQ202475-145225.mp4Thanks |
Hi, no problem :) When inserting the content using JSON (e.g., Similar, using HTML you can use The inline style is good when working with math expressions inside text, e.g., When using the auto-conversion of the editor Let me know if this fixes your issue! |
@aarkue Thanks, this is useful for me, thanks for your serious reply |
Requires deleting the trailing
$
and re-adding it for it to work.Screen.Recording.2024-06-08.at.10.13.10.mov
The text was updated successfully, but these errors were encountered: