Last active
October 28, 2020 06:24
-
-
Save blasterpistol/21d2bb1964a8f042dde4c189a28d9d94 to your computer and use it in GitHub Desktop.
TinyMCE formatting for contentEditable=false elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To resolve all quirks need to use custom elements | |
// Demo: http://fiddle.tinymce.com/7whaab | |
tinymce.init({ | |
selector: 'textarea', | |
// custom html elements will force tinymce to wrap var-inline when formatting | |
// and apply formatting inside of var-block (as it should be) | |
custom_elements: "~var-inline,var-block", | |
setup: (editor) => { | |
// temporary remove content editable false before commands and apply back then | |
editor.on("BeforeExecCommand", () => { | |
editor.selection.editor | |
.getBody() | |
.querySelectorAll("[contenteditable=false]") | |
.forEach((n) => { | |
n.setAttribyte("noneditable", "true"); | |
n.removeAttribute("contenteditable"); | |
}); | |
}); | |
editor.on("ExecCommand", () => { | |
editor | |
.getBody() | |
.querySelectorAll("[noneditable="true"]") | |
.forEach((n) => { | |
n.setAttribute("contenteditable", "false"); | |
n.removeAttribute("noneditable"); | |
}); | |
}); | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea> | |
<var-inline contenteditable="false">Some inline placeholder</var-inline> | |
<var-block contenteditable="false">Some block placeholder (tables or images)</var-block> | |
</textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment