问题
Using a custom button, I add a paragraphe with a class and some content, like so :
<p class="mce-new-class">my custom content</p>
When I press enter after such a paragraph, TinyMCE will automatically add a new paragraph using the exact same class :
<p class="mce-new-class">my custom content</p>
<p class="mce-new-class"> </p>
I'd like to only have a new paragraph but without the class :
<p class="mce-new-class">my custom content</p>
<p> </p>
I've tried this :
tinymce.init({
...
setup: function (ed) {
ed.on('keydown',function(e) {
if(e.keyCode == 13){
ed.selection.setContent('<p> </p>');
return false;
}
});
}
});
But this applies to all situations and will brake other usefull situations such as replicating a list element on "enter press"
Any help would be much appreciated
回答1:
Found out a solution :
...
setup: function (ed) {
ed.on('keydown',function(e) {
if(e.keyCode == 13){
if(ed.dom.hasClass(ed.selection.getNode(), 'mce-new-class')){
ed.selection.setContent('<p> </p>');
return false;
} else {
return true;
}
}
});
},
...
来源:https://stackoverflow.com/questions/45392375/tinymce-dont-replicate-class-when-adding-a-new-paragraph-on-enter