简体   繁体   中英

TinyMCE force content into into an ordered list (ol)

Is there a way to force the editor to begin with an ol so when the user clicks enter , it will automatically go to a new li . The user should also not be able to exit the ol , so when they click enter on an empty line, it should stay in the ol .

I have tried forced_root_block : 'li' and forced_root_block : 'ol' but they don't seem to do anything.

I have also looked through TinyMCE's documentation but couldn't find any way to do this. Thanks!

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');
                }
            }
        });
    }
});

The paste as text plugin is so when the user pastes a large number of text, it won't break the li

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM