KutePHP
KutePHP

Reputation: 2236

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",
        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?

Upvotes: 18

Views: 44255

Answers (11)

davomarti
davomarti

Reputation: 1

newline_behavior: 'linebreak'

worked for tinymce 7.3.0

Upvotes: 0

Gabbodrummer
Gabbodrummer

Reputation: 117

In the latest version, adding these parameters does not work:

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

this parameter must be added instead:

newline_behavior: 'linebreak'

as reported here: newline_behavior

Upvotes: 1

Ghazi Waleed
Ghazi Waleed

Reputation: 24

Just add

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

anywhere in tinymce.init

Upvotes: 1

Pramod
Pramod

Reputation: 848

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

Upvotes: 1

David
David

Reputation: 11

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

Upvotes: 1

Mikle Gardener
Mikle Gardener

Reputation: 21

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

Upvotes: 2

Thanh Trung
Thanh Trung

Reputation: 3804

Simply add forced_root_block : false

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

Works like a charm!

Upvotes: 26

Lucien Boix
Lucien Boix

Reputation: 1009

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

Upvotes: 10

Nookeen
Nookeen

Reputation: 465

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

Upvotes: 10

gavlinski
gavlinski

Reputation: 43

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

Upvotes: 4

Thariama
Thariama

Reputation: 50832

Instead try:

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

Upvotes: 15

Related Questions