TinyMCE粘贴麻烦

时间:2020-05-21 08:40:59

标签: tinymce

我在配置编辑器时遇到麻烦,我正在尝试删除中断。 当我从其他应用程序(单词,写字板...)粘贴文本时。它会生成<p>&nbsp;</p> 哪里有休息,但每个段落之间的间隔太大(因为我认为p元素的默认边距) 所以我尝试不使用pase生成段落

paste_create_paragraphs: false,
paste_create_linebreaks: false,

,但它仍会生成<p>标签。 然后,我尝试使用paste_postprocess强制删除<p>&nbsp;</p>,但没有任何作用。

这是我完整的TinyMCE初始化

tinymce.init({
    selector: 'textarea',
    height: 200,
    theme: 'modern',
    plugins: 'print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern help',
    toolbar1: 'formatselect | bold underline italic strikethrough | backcolor | alignleft aligncenter alignright alignjustify | table ',
    toolbar2: 'numlist bullist | outdent indent | removeformat | subscript superscript | link unlink',
    fontsize_formats: '7px 8px 9px 10px 11px 12px 13px 14px 15px 16px 17px 18px 19px 20px 21px 22px 23px 24px 25px 26px 27px 28px 29px 30px',
    image_advtab: true,
    block_formats: 'Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3;Header 4=h4;Header 5=h5;Header 6=h6;',
    image_class_list: [
      { title: 'Immagine Responsive', value: 'img-responsive img-fluid' },
      //{ title: 'Lightbox', value: 'lightbox' },
    ],
    theme_advanced_resize_horizontal: false,
    paste_create_paragraphs: false,
    paste_create_linebreaks: false,
    paste_auto_cleanup_on_paste: true,
    paste_postprocess: function (pl, o) {
        // remove &nbsp
        o.node.innerHTML = o.node.innerHTML.replace(/&nbsp;/ig, "");
        // just a try
        o.node.innerHTML = o.node.innerHTML.replace("<p>&nbsp;</p>", "");
      }
});

1 个答案:

答案 0 :(得分:0)

解决了在paste块中添加plugins

tinymce.init({
    selector: 'textarea',
    height: 200,
    theme: 'modern',
    // ADDED "paste" plugin
    plugins: 'paste  print preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern help',
    toolbar1: 'formatselect | bold underline italic strikethrough | backcolor | alignleft aligncenter alignright alignjustify | table ',
    toolbar2: 'numlist bullist | outdent indent | removeformat | subscript superscript | link unlink',
    fontsize_formats: '7px 8px 9px 10px 11px 12px 13px 14px 15px 16px 17px 18px 19px 20px 21px 22px 23px 24px 25px 26px 27px 28px 29px 30px',
    image_advtab: true,
    block_formats: 'Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3;Header 4=h4;Header 5=h5;Header 6=h6;',
    image_class_list: [
      { title: 'Immagine Responsive', value: 'img-responsive img-fluid' },
      //{ title: 'Lightbox', value: 'lightbox' },
    ],
    theme_advanced_resize_horizontal: false,
    paste_create_paragraphs: false,
    paste_create_linebreaks: false,
    paste_auto_cleanup_on_paste: true,
    paste_postprocess: function (pl, o) {
        // remove &nbsp
        o.node.innerHTML = o.node.innerHTML.replace(/&nbsp;/ig, "");
        // just a try
        o.node.innerHTML = o.node.innerHTML.replace("<p>&nbsp;</p>", "");
      }
});
相关问题