我想粘贴格式的文本从MS Word保持格式相同在我的tinyMCE编辑器

I want to paste formatted text from MS Word by keeping the formation same in my tinyMCE editor

本文关键字:格式 tinyMCE 我的 编辑器 MS 文本 Word      更新时间:2023-09-26

我使用的是tinyMCE wysiwyg编辑器。我想在我的编辑器中保持格式相同的情况下粘贴MS Word中的格式化文本。

tinymce.init({
    selector: "textarea#main_content",
    menubar:false,
    height: 344,
    min_height:344,
    font_size: 20,
    resize: false,
    browser_spellcheck : true,
    contextmenu: false,
    'plugins': [
        "link",
        "searchreplace",
        "paste"
    ],
    paste_auto_cleanup_on_paste : true,
    paste_word_valid_elements: "b,strong,i,em,h1,h2,u,p,ol,ul,li,a[href]",
    paste_remove_styles: false,
    paste_retain_style_properties: "all",
    paste_preprocess : function(pl, o) {
        o.content = strip_tags( o.content,'<b><u><i><p><br><a><ul><ol><li><strong><em><span><h1><h2><h3>');
    },
    paste_postprocess : function(pl, o) {
        o.node.innerHTML = o.node.innerHTML;
    },
    toolbar: "undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link pasteword",
    setup : function(ed) {
      ed.on('keyup', function(e) {
           window.clearTimeout(keyupTimer);
           keyupTimer = setTimeout(function(){
                updateTxtarea();
                seo_validate(1);
                instant_word_count();
           },2000);
      });
      ed.on('focus', function(e) {
            if($('.skin-toolbox-toggle').hasClass('toolbox-open')){
                $('.skin-toolbox-toggle').trigger('click');
            }
      });
   }
});

我正在使用上面的代码。粗体,斜体,下划线,ul, li,超链接的工作,这些都是好的,但我需要字体大小,文本对齐,颜色也保持不变,在我的tinyMCE编辑器相同的MS word。

我已经谷歌了很多,但没有找到确切的解决方案。请帮帮我....

paste_retain_style_properties: "all"

应该是您所寻找的,但由于这不起作用,也许可以尝试用color font-size…

替换all

或者将paste_auto_cleanup_on_paste设置为false,因为文档并没有真正说明这实际上是做什么的

尝试将"span"添加到paste.word. validate .elements列表

我看到它被用来包含颜色、大小和字体信息