2
votes

Below is my current Tinymce configuration which will remove all the style/formatting/html tags and paste as a plain text, but my customer want to paste the table into it. So I would like improve my tinymce to be able to paste the table (only) when we copy and paste from 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);
                });
            }
        });

EDITED below is my final code

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)
{
}
2

2 Answers

2
votes

The solution is to use paste_preprocess. In this SO-thread you will find a way to paste as plain text, but to keep tables define table, tbody, td, tr to be not stripped out when pasted

1
votes

I find a solution for copy - paste tinyMCE 4.0

if you using this basic example source

<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>

remove " paste " option from plugins section;

like this;

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

Now you can paste (everything ms word , html page etc..) to tinyMCE editor

maybe ,might be help