TinyMCE 将内容强制放入有序列表中(ol)
TinyMCE force content into into an ordered list (ol)
有没有办法强制编辑器以 ol
开头,这样当用户单击 enter
时,它会自动转到新的 li
。用户也应该无法退出 ol
,因此当他们在空行上单击 enter
时,它应该停留在 ol
中。
我已经尝试了 forced_root_block : 'li'
和 forced_root_block : 'ol'
,但他们似乎什么也没做。
我也查看了 TinyMCE 的文档,但找不到任何方法来执行此操作。谢谢!
tinymce.init({
plugins: "link, paste",
toolbar: 'numlist',
valid_elements : "-ol,-li",
menubar: false,
paste_as_text: true,
setup: function (editor) {
editor.on("init", function() {
editor.execCommand('InsertOrderedList');
});
// This forces all 'enter' and 'backspace' keys to create an 'ol li' element
editor.on('keyup', function(e) {
if (e.keyCode == 13 || e.keyCode == 8){
if (tinyMCE.activeEditor.selection.getNode().nodeName.toLowerCase() != 'li'){
editor.execCommand('InsertOrderedList');
}
}
});
}
});
粘贴为文本插件是这样的,当用户粘贴大量文本时,它不会破坏 li
有没有办法强制编辑器以 ol
开头,这样当用户单击 enter
时,它会自动转到新的 li
。用户也应该无法退出 ol
,因此当他们在空行上单击 enter
时,它应该停留在 ol
中。
我已经尝试了 forced_root_block : 'li'
和 forced_root_block : 'ol'
,但他们似乎什么也没做。
我也查看了 TinyMCE 的文档,但找不到任何方法来执行此操作。谢谢!
tinymce.init({
plugins: "link, paste",
toolbar: 'numlist',
valid_elements : "-ol,-li",
menubar: false,
paste_as_text: true,
setup: function (editor) {
editor.on("init", function() {
editor.execCommand('InsertOrderedList');
});
// This forces all 'enter' and 'backspace' keys to create an 'ol li' element
editor.on('keyup', function(e) {
if (e.keyCode == 13 || e.keyCode == 8){
if (tinyMCE.activeEditor.selection.getNode().nodeName.toLowerCase() != 'li'){
editor.execCommand('InsertOrderedList');
}
}
});
}
});
粘贴为文本插件是这样的,当用户粘贴大量文本时,它不会破坏 li