14

当您从 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>

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

4

6 回答 6

16

将这些行添加到您的tinymce.init({ });

例子:

tinymce.init({
    forced_root_block : "", 
    force_br_newlines : true,
    force_p_newlines : false,
});
于 2013-08-07T23:32:39.960 回答
3

这会很有帮助。

添加到您的tinymce.yml文件中

forced_root_block : "" 

force_br_newlines : true

force_p_newlines : false
于 2014-03-14T05:45:48.977 回答
0

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

于 2013-06-12T07:20:46.233 回答
0

感谢普拉哈拉德·加格!

我有同样的问题,我通过阅读这个主题解决了它:https ://stackoverflow.com/a/22397116/14491024

这是我每次添加的代码 <p<br/<br/</p



很烦人)

函数 HTMLeditor( 参数) {

$('#exampleModalCenter').modal('show');

tinymce.init({
    height: 500,
    selector: ".modal-body",
    theme: 'modern',
    plugins: [
        'advlist autolink lists link image charmap print preview hr anchor pagebreak',
        'searchreplace wordcount visualblocks visualchars code fullscreen',
        'insertdatetime media nonbreaking save table contextmenu directionality',
        'emoticons template paste textcolor colorpicker textpattern imagetools'
    ],
    toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    toolbar2: 'print preview media | forecolor backcolor emoticons ', 
    image_advtab: true,

    setup: function (editor) {
        editor.on('init', function (e) {
            editor.setContent(parameters);
        });
    }

});

}

这是解决的问题:

函数 HTMLeditor( 参数) {

$('#exampleModalCenter').modal('show');

tinymce.init({
    height: 500,
    selector: ".modal-body",
    theme: 'modern',
    plugins: [
        'advlist autolink lists link image charmap print preview hr anchor pagebreak',
        'searchreplace wordcount visualblocks visualchars code fullscreen',
        'insertdatetime media nonbreaking save table contextmenu directionality',
        'emoticons template paste textcolor colorpicker textpattern imagetools'
    ],
    toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    toolbar2: 'print preview media | forecolor backcolor emoticons ', 
    image_advtab: true,

    //remove <p><br /><br /></p>
    forced_root_block: "" ,
    force_br_newlines: true,
    force_p_newlines: false,


    setup: function (editor) {
        editor.on('init', function (e) {
            editor.setContent(parameters);
        });
    }

});

}

于 2020-12-26T15:00:13.043 回答
0

将此添加到您的 functions.php 文件中,标准 p-tags 标记将通过向 tiny_mce_before_init 钩子添加一些参数来删除。如果您想了解它是如何工作的,可以在此页面上进一步阅读:https ://codex.wordpress.org/TinyMCE

////////////////////////////////////////////////////////////////////////
//////////REMOVE STANDARD <P> FROM TINYMCE EDITOR/////////////////////////
///////////////////////////////////////////////////////////////////////
function my_format_TinyMCE( $in ) {
$in['forced_root_block'] = "";
$in['force_br_newlines'] = TRUE;
$in['force_p_newlines'] = FALSE;
return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );
于 2017-02-10T10:36:10.313 回答
0

在 BoundField 中使用 HtmlEncode="false"

<asp:BoundField DataField="PostContent" HtmlEncode="false" /> 
于 2020-05-03T19:20:05.367 回答