insert line break instead of

in TinyMCE

前端 未结 8 1786
难免孤独
难免孤独 2021-02-04 07:55

I have initialised TinyMCE as follows. I want to force line breaks when user presses enter and not the paragraphs. I\'m trying following, but not working. I\'m using TinyMCE ve

相关标签:
8条回答
  • 2021-02-04 08:18

    I faced the same situation with TinyMCE 4. All my "Enter" (keyboard) resulted in a new <p>&nbsp</p> injected.

    I didn't want to use forced_root_block : false so I figured something out in the tinymce.init function (each empty paragraph will be cleaned directly):

    setup : function(editor) {
    
                editor.on('PostProcess', function(ed) {
                    // we are cleaning empty paragraphs
                    ed.content = ed.content.replace(/(<p>&nbsp;<\/p>)/gi,'<br />');
                });
    
            }
    

    https://www.tinymce.com/docs/configure/integration-and-setup/#setup https://www.tinymce.com/docs/api/class/tinymce.editor/#postprocess

    0 讨论(0)
  • 2021-02-04 08:23

    Insert in theme functions.php the following code:

        add_filter( 'tiny_mce_before_init', 'my_switch_tinymce_p_br' ); 
    
        function my_switch_tinymce_p_br( $settings ) {
            $settings['forced_root_block'] = 'br';
            return $settings;
        }
    
    0 讨论(0)
  • 2021-02-04 08:32

    Instead try:

    force_p_newlines : false,
    force_br_newlines : true,
    convert_newlines_to_brs : false,
    remove_linebreaks : true,    
    
    0 讨论(0)
  • 2021-02-04 08:32

    What worked for me was:

    tinymce.init({
        ...
        force_br_newlines : true,
        force_p_newlines : false,
        forced_root_block : ''
    });
    

    Each linebreak is producing br tag with these settings.

    SOURCE: http://www.tinymce.com/wiki.php/Configuration3x:force_br_newlines

    0 讨论(0)
  • 2021-02-04 08:32

    The "forced_root_block : false" option works fine for TinyMCE 4.0.

    0 讨论(0)
  • 2021-02-04 08:35

    TinyMCE On Mozilla Firefox adds <div> instead <br> or <p>.

    I found the solution:

    Open Mozilla Firefox and put in the address: about:config

    Search the option and turn false: editor.use_div_for_default_newlines

    0 讨论(0)
提交回复
热议问题