How can I remove p tags that are auto added within tinymce

前端 未结 11 1880
挽巷
挽巷 2020-12-06 04:46

I am using tinymce 4.0.1 and it automatically adds p tags when you either start typing or hit enter. How can I dynamically remove these p tags and then reinsert the content

相关标签:
11条回答
  • 2020-12-06 05:04

    Are you looking for: forced_root_block : '', force_br_newlines : true, force_p_newlines : false,

    0 讨论(0)
  • 2020-12-06 05:08

    You can remove "p" tag by adding forced_root_block : false to your tinymce setup or you can hide the status bar by statusbar: false

    0 讨论(0)
  • 2020-12-06 05:08

    How about

    $("p").each(function(){$(this).parent().append($(this).html()); $(this).remove()})
    
    0 讨论(0)
  • 2020-12-06 05:08

    Can you simply tweak what TinyMCE puts into the database when you display it? See my post for the same thing for Rails.

    var str = "{TinyMCE HTML string}"; /* however you get it */
    str = str.replace(/^\<p\>/,"").replace(/\<\/p\>$/,"");
    

    Here you are removing the beginning and ending p tag of the whole TinyMCE HTML when you display it. Doesn't mess with other p tags or the TinyMCE config.

    Explanation of the regex expression (removed \'s for ease of reading):

    ^<p> - find <p> at the start of the string (^) and replace it with nothing.
    </p>$ - find </p> at the end of the string ($) and replace it with nothing.
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-06 05:09

    Add this only in call javascript:

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