开发者

insert line break instead of <p> in TinyMCE

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 version 3_3_8.

tinyMCE.init({
        mode: "exact",
        theme: "advanced",
 开发者_如何学Python       elements: "textAreaId",
        cleanup: false,
        theme_advanced_toolbar_location: "",
        theme_advanced_buttons1: "",
        theme_advanced_buttons2: "",
        theme_advanced_buttons3: "",
        height: 200,
        width: 300,
    forced_root_block : false,
    force_br_newlines : true,
    force_p_newlines : false,
        oninit: InitPosition
    }); //init ends

I tried to define forced_root_block : "", but still it is not working.

What am I doing wrong?


Simply add forced_root_block : false

Or if you want a wrapper: forced_root_block : 'div',

Works like a charm!


Instead try:

force_p_newlines : false,
force_br_newlines : true,
convert_newlines_to_brs : false,
remove_linebreaks : true,    


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


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


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


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


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


in tinyMCE 5 I needed to add 1 extra parameter

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


Just add

force_br_newlines : true,
force_p_newlines : false,
forced_root_block : false,

anywhere in tinymce.init

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜