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
Is it possible to add a Latex code via a function or method? #474
Comments
@JiHong88 Is this possible to do? |
@dgandhi1993 Sorry for the late reply. |
@JiHong88 I don't have any links at the moment. But this would be similar to any markdown editor wherein you type latex code and it gets converted into its equivalent formula. In SunEditor's reference, this is similar to #414 where we used a function call to add the image URL, similarly here we would use a function call to convert the selected text to its latex equivalent. |
@dgandhi1993 I will check it after the 2.33.0 version update. |
@JiHong88 Is it possible for you to give a workaround to access the method on the submit button in the Formula modal? |
@JiHong88 Can we add this to milestone 2.34.0? |
@dgandhi1993 Yeah, I'll update this issue at next version. |
Hi @JiHong88 I understand that you might be busy, but can you help me with a workaround for this problem? |
Hi @dgandhi1993 |
Hi @JiHong88 . I understand. It's really great to see what you have built. Truly amazing! What I am looking for is a way to convert some selected text in the editor into its Latex equivalent HTML code. I'll share the use case I am trying to solve. I have a text string on my clipboard which has relevant Latex code in it between the symbols "(" and ")". I wish to extract this code from the string and replace it with its Latex (or Katex) HTML code and then paste inside the editor so the user does not need to type in the formula again. I hope I was able to convey the use case well. Let me know if you have any queries. |
@dgandhi1993 Thank you : ) clipboard: Is it correct that I understand? |
@JiHong88 That's correct. However, also consider the fact that there might be text (possibly with Latex or images) existing in the editor before I paste anything. |
@dgandhi1993 |
@JiHong88 Awesome. That would be great! |
@JiHong88 can you please help with the example code? |
@dgandhi1993 I will definitely make an example this week. |
@dgandhi1993 Sorry for the late reply. You can use below example after the version update. const editor = suneditor.create();
editor.onPaste = (e, cleanData, maxCharCount, core) => {
// replace () > span.katex
const data = cleanData.replaceAll("(", '<span class="temp-katex">').replaceAll(")", "</span>");
// set attribute "data-exp"
// create html string
let reRender = false;
let html = "";
const children = core._d.createRange().createContextualFragment(data).childNodes;
for (let i = 0, len = children.length, node; i < len; i++) {
node = children[i];
if (node.className === "temp-katex") {
node.className = "katex";
node.setAttribute("data-exp", node.textContent);
reRender = true;
}
html += node.outerHTML || node.textContent;
}
// Re-render the "katex" tag in the "cleanHTML" function.
return !reRender || core.cleanHTML(html, core.pasteTagsWhitelistRegExp);
} I'll notify you after the version update. |
The 2.34.0 version has been updated. |
@JiHong88 This code has no effect. The function is not even called when I paste. I tried printing Ideally if this is my sample clipboard text: The output in the editor should look like this (ignore the line break): |
@JiHong88 Can you please look into this |
@dgandhi1993 It is not normal for the onPaste function not to be called. |
It is exactly the same code you shared. Also sharing the options I used.
|
@dgandhi1993 Is onPaste being overridden elsewhere? |
@JiHong88 My bad. onPaste was actually getting overridden as the editor instance was getting recreated. Resolved it. Now works perfectly. Thanks a lot, man! Really appreciate it. |
Currently one has to open the formula modal, input the latex code into the field and then submit it. Instead, is there a possibility to simply pass the input value to a function and add the equivalent latex code to the editor?
What would be amazing is if we can type the latex inside the editor, select the latex code and click on an editor button that converts it into its preview.
The text was updated successfully, but these errors were encountered: