tinymce adding p tags automatically?

后端 未结 4 1092
名媛妹妹
名媛妹妹 2020-12-13 23:57

Im using tinymce and saving it to a database.

When I edit the saved content using tinymce and save again, it inserts a p tag at the beginning.

Editing the co

相关标签:
4条回答
  • 2020-12-14 00:06

    From tinymce.js v4.1.10 code:

    newBlockName = (settings.force_p_newlines ? 'p' : '') || settings.forced_root_block;
    

    So the key to avoid <p> seems to be as stated before

    settings.force_p_newlines = false
    

    and

    settings.forced_root_block = ''
    
    0 讨论(0)
  • 2020-12-14 00:16

    TinyMce automatically add "<p>" in new lines. You can set this option in tinyMce initialization like this:

      tinyMCE.init({
          mode : "textareas",
          theme : "advanced",
          force_br_newlines : false,
          force_p_newlines : false,
          forced_root_block : '',
      });
    

    Hope it will help

    Fonski

    0 讨论(0)
  • 2020-12-14 00:21

    I am sure that @Fonski answer is correct but thought I would update this for anyone else that did was confused as to where to put the code. I placed the following in my _config.php file to get it to work:

    $defaultEditorConfig = HtmlEditorConfig::get('cms');
    $defaultEditorConfig->setOptions(
        array(
            'mode'              => 'textareas',
            'theme'             => 'advanced',
            'force_br_newlines' => false,
            'force_p_newlines'  => false,
            'forced_root_block' => ''
        )
    );
    

    Note: If you just want to remove the p tag that automatically wraps image tags (etc) all you need to set is the 'forced_root_block' => '' option.

    EDIT: This advice is for those using SilverStripe, I posted this thinking the questions was SilverStripe specific.

    0 讨论(0)
  • 2020-12-14 00:21

    For me it worked by making "force_br_newlines : true" instead of false.

     tinyMCE.init({
          mode : "textareas",
          theme : "advanced",
          force_br_newlines : true,
          force_p_newlines : false,
          forced_root_block : ''
      });
    

    I hope it helps

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