【问题标题】:Paste table html tag to tinymce textbox将表格 html 标记粘贴到 tinymce 文本框
【发布时间】:2012-10-25 03:17:47
【问题描述】:

以下是我当前的 Tinymce 配置,它将删除所有样式/格式/html 标签并粘贴为纯文本, 但我的客户想将表格粘贴到其中。所以我想改进我的tinymce,以便在我们从ms word复制和粘贴时能够(仅)粘贴表格。

tinyMCE.init({
            theme: "advanced",
            mode: "exact",
            elements: "txtTextbox1",
            plugins : "paste,table,directionality,preview,iespell,wordcount,style",        
            theme_advanced_buttons1: "bold,italic,underline,|,cut,copy,paste,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,undo,redo,|,preview,iespell",
            theme_advanced_buttons2: "tablecontrols,|,link,unlink",
            //theme_advanced_buttons3: "tablecontrols,|,link,unlink",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            force_p_newlines: false,
            force_br_newlines: true,
            forced_root_block: '',
            paste_convert_middot_lists: false,
            paste_text_sticky: true,
            paste_strip_class_attributes: "all",
            paste_remove_styles: true,
            paste_remove_spans: true,
            paste_block_drop: true,
            paste_text_sticky_default: true,

            setup: function (ed) {
                ed.onInit.add(function (ed) {
                    ed.pasteAsPlainText = true;
                    ed.controlManager.setActive("pastetext", true);
                });
            }
        });

已编辑 下面是我的最终代码

tinyMCE.init
        ({
            theme: "advanced",
            mode: "exact",
            elements: "txtTextbox1",
            plugins : "paste,table,directionality,preview,iespell,wordcount,style",        
            theme_advanced_buttons1: "bold,italic,underline,|,cut,copy,paste,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,undo,redo,|,preview,iespell",
            theme_advanced_buttons2: "tablecontrols,|,link,unlink",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            force_p_newlines: false,
            force_br_newlines: true,
            forced_root_block: '',
            paste_convert_middot_lists: false,            

            paste_preprocess : function(pl, o) 
            {  
                o.content = strip_tags( o.content,'<table><tr><td>' );
            },            
        });


function strip_tags (str, allowed_tags)
{
}

【问题讨论】:

    标签: tinymce


    【解决方案1】:

    我找到了复制粘贴 tinyMCE 4.0 的解决方案

    如果你使用这个基本示例源

    <script type="text/javascript">
    tinymce.init({
        selector: "textarea",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste moxiemanager"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });
    </script>
    

    从插件部分删除“粘贴”选项;

    这样;

       plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu moxiemanager"
        ],
    

    现在您可以将(所有 ms 字、html 页面等)粘贴到 tinyMCE 编辑器

    也许,也许有帮助

    【讨论】:

    • 谢谢.. 这个解决方案帮助我在最后一周搜索了很多
    【解决方案2】:

    解决方案是使用 paste_preprocess。在this SO-thread 中,您会找到一种粘贴为纯文本的方法,但要保持表格定义table、tbody、td、tr 在粘贴时不会被剥离

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      相关资源
      最近更新 更多