You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing an extension that pulls blocks of text from an endpoint that are formatted in MD, and i want to be able insert them inside the editor with the formatting. I am using insertText() for this.
This is where the problem is if the user is in WYSIWYG mode the text gets escaped. I tried to see what the mode is and try and convert the text to html but it gets escaped again. I tried getting the mdEditor from the editor object but this returns an error saying insertText does not exist, and if use replaceSelection directly it only works when the editor is in markdown mode anyway. As a final resort I tried switching back and fort the mode which does work but causes jumps and is bad ux.
So my question is is there a way to insert MD text and retain formatting using JavaScript even when the current view is in WYSIWYG.
The text was updated successfully, but these errors were encountered:
NEVERMIND. This doesn't work for this general case for Markdown formatted text. The solution only works for trying to add unescaped text for a custom block.
Underscore escaping seems to be called regardless if this is first time or last time. It seems to always be happening.
It doesn't seem like this project is still maintained... but I ran into this problem as well and came up with a very hacky solution.
You'll have to create your own plugin and create you own command:
Then you can call your function where you want to insert code:
let isWysiwygMode = editor.isWysiwygMode();
if (isWysiwygMode) {
let [ns, ne] = editor.getSelection()
editor.exec("unescapedInsertCommand", "**This is markdown text.**");
editor.changeMode('markdown', true)
editor.changeMode('wysiwyg', true)
editor.setSelection(ns, ne); // if you want the cursor to be where it was before swapping the modes...
} else {
// use regular insertText in markdown mode
editor.insertText("**This is markdown text.**");
}
Yes, you have to switch it back and forth from markdown to wysiwyg mode really fast for the markdown to be rendered correctly in WYSIWYG mode...
Don't ask me why or how... This is the only solution I was able to come up with after 6 hours of hacking.
If anyone can expand on this and make it less hacky, I would definitely welcome others to try.
I'm writing an extension that pulls blocks of text from an endpoint that are formatted in MD, and i want to be able insert them inside the editor with the formatting. I am using insertText() for this.
This is where the problem is if the user is in WYSIWYG mode the text gets escaped. I tried to see what the mode is and try and convert the text to html but it gets escaped again. I tried getting the mdEditor from the editor object but this returns an error saying insertText does not exist, and if use replaceSelection directly it only works when the editor is in markdown mode anyway. As a final resort I tried switching back and fort the mode which does work but causes jumps and is bad ux.
So my question is is there a way to insert MD text and retain formatting using JavaScript even when the current view is in WYSIWYG.
The text was updated successfully, but these errors were encountered: