删除tinyMCE中的额外p标记

Piu*_*ath 14 tinymce

当您从word文档复制并粘贴到tinyMCE编辑器时,有时会出现不需要的<p>标记:

<p>&nbsp;</p>
<div class="starpasspro-example-question">
   <p><strong>Example: Levels of strategy</strong></p>
   <p>Microsoft is one of the world&rsquo;s largest organisations, providing corporate solutions to businesses throughout the world to help them realise their fullest potential. At Microsoft, there are three levels of strategy as follows:</p>
</div>
<p>&nbsp;</p>
Run Code Online (Sandbox Code Playgroud)

这里生成的代码我想以<p>任何方式删除标签吗?

rka*_*yan 15

在你的添加这些行 tinymce.init({ });

例:

tinymce.init({
    forced_root_block : "", 
    force_br_newlines : true,
    force_p_newlines : false,
});
Run Code Online (Sandbox Code Playgroud)


Tha*_*ama 0

是的,这是可能的。有一种安全的方法可以删除您想要删除的所有 html 元素(您可以定义要保留的内容)。它是通过使用 tinymce 配置参数paste_preprocess和自定义函数来实现的strip_tags在这里查看一下。