Processing
 

When I copy paste content from MS word to TinyMCE editor formatting is totally changed / corrupted.

20/09/2016 14:52#1

Joined at: 4 months ago

Post: 1

Thank: 0

Thanked: 0

I am using TinyMCE editor 3.5.11. If I type, everything is fine. No issues. I am using properties paste_retain_style_properties: "all", & paste_auto_cleanup_on_paste = false. When I copy paste content from MS word to TinyMCE editor, then some of the formatting is lost. If data has bullets or table, then its formatting is totally changed / corrupted. I have a file richTextScripts.jspf in the project, which has lots of formatting related code. I wonder if that is changing font and other formatting. Please provide your suggestions. Part of the code is as given below:

tinyMCE.init({ mode : "exact", theme : "advanced", inline_styles : false, elements:"<%=request.getAttribute("tinyMCEElements")%>", plugins : "<%=pluginList%>",

theme_advanced_buttons1 : "fullscreen,search,spellchecker,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,tablecontrols,|,hr,pastetext,removeformat", theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,forecolor,backcolor,nonbreaking,charmap,|,link,unlink<%=!isStandard?"":",|,image"%>", theme_advanced_buttons3: "<%=!isAutoFill?"":",defaultcontent,mainBodyContent,confInstruction,confInsNoInterview,questionnaire,globalvars"%>", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : <%= isResizing %>, theme_advanced_resizing_use_cookie : 0, theme_advanced_resize_horizontal : <%= isResizeHorizontal %>, theme_advanced_resizing_min_width : 650, theme_advanced_resizing_min_height : 160, theme_advanced_path: false, relative_urls : false, convert_urls : false, paste_auto_cleanup_on_paste: false, paste_convert_middot_lists: <%= isWordCleanupEnabled %>, paste_retain_style_properties:"all", paste_postprocess: function(pl, o) {cleanPasteRecursive(pl.editor.getDoc(), o.node);}, convert_fonts_to_spans: true, font_size_style_values : "12pt", spellchecker_languages : "+English=en-us,German=de-de", spellchecker_rpc_url    : "<%=request.getContextPath()%>/jmyspell-spellchecker",  external_image_list_url : "<%=request.getContextPath()%>/tiny_mce/imagelist.jsp", valid_elements : '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|float],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title],strong/b,em/i,strike/s,u,style,#p[align],-ol[type|compact|start],-ul[type|compact],-li,br,img[longdesc|src|border|alt=|hspace|vspace|width|height|align],-sub,-sup,-table[border|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div[align],-span,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],bdo,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],small,tt,big,address,pre', init_instance_callback: "initInstanceCallback", content_css: "/PolicyAtlas/tiny_mce/themes/advanced/skins/default/richtextedt.css", formats : {     alignleft : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div', 'classes' : 'alignleft' },     aligncenter : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div', 'classes' : 'aligncenter' },     alignright : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div', 'classes' : 'alignright' },     alignfull : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div', 'classes' : 'alignfull' },     bold : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'classes' : 'bold' },     italic : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'classes' : 'italic' },     underline : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'classes' : 'underline' },     strikethrough : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'classes' : 'strikethrough' },     fontname : { 'selector' : 'h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'toggle': false, 'styles' : {'font-family' : '%value'}},     fontsize : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'styles' : {'font-size' : '%value'}},      forecolor : { 'selector' : 'p,h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'styles' : {'color' : '%value'}},     hilitecolor : { 'selector' : 'h1,h2,h3,h4,h5,h6,td,th,div,table', 'inline' : 'span', 'toggle': false, 'styles' : {'background-color' : '%value'}} } }); 

function cleanPasteRecursive(doc, node) { try {

tinymce.each(node.childNodes, function(child){          try {      if (child.childNodes.length > 0) {         cleanPasteRecursive(doc, child);     }     } catch(e){} // ignoring errors where childNodes is undefined on IE7     var newClass = null;      if (child.nodeName == "strong" || child.nodeName == "STRONG" || child.nodeName == "b" || child.nodeName == "B") {         newClass = "bold";     }     else if (child.nodeName == "em" || child.nodeName == "EM" || child.nodeName == "i" || child.nodeName == "I") {         newClass = "italic";     }     else if (child.nodeName == "strike" || child.nodeName == "STRIKE" || child.nodeName == "s" || child.nodeName == "S") {         newClass = "strikethrough";     }     else if (child.nodeName == "u" || child.nodeName == "U") {         newClass = "underline";     }      if (newClass) {         if (child.childNodes.length == 1 && (child.childNodes[0].nodeName == "span" || child.childNodes[0].nodeName == "SPAN")) {             // collapse spans if possible             if (child.childNodes[0].className)                 newClass = newClass + " " + child.childNodes[0].className;             child.childNodes[0].className = newClass;             node.replaceChild(child.childNodes[0], child);         }         else {             newElem = doc.createElement("span");             newElem.className = newClass;             newElem.innerHTML = child.innerHTML;             node.replaceChild(newElem, child);         }     }     if (typeof child.className != "undefined"){         pos = child.className.indexOf("outputText");         if (pos >= 0) {             child.className = child.className.substr(0, pos) + child.className.substr(pos+10);         }     } }); } catch(e){} // ignoring errors where childNodes is undefined on IE7 

}

Similar articles

VBA regex matching over two lines

4 months ago - Reply: 1 - Views: 44

Table output to Word-2011 from Rstudio using knit

4 months ago - Reply: 0 - Views: 28

Write a Collection of paragraphs into a new document

4 months ago - Reply: 1 - Views: 70

how to write paragraphs without show to document

4 months ago - Reply: 1 - Views: 66

numericals in word macro

4 months ago - Reply: 1 - Views: 45

Can not find proofing tools

4 months ago - Reply: 0 - Views: 1

Possible values for <w:outlineLvl> in Word OOXML

4 months ago - Reply: 1 - Views: 7

C# restrict editing partial word paragraph

4 months ago - Reply: 2 - Views: 142

Macro translation Please (possible virus)

4 months ago - Reply: 1 - Views: 34

Doc/Docx Fastest Reading Method for Searching

4 months ago - Reply: 0 - Views: 1

Save embedded file / content from word

4 months ago - Reply: 0 - Views: 5

Counting words in Word document, including footnores

4 months ago - Reply: 1 - Views: 22

c# access extract word ole object

4 months ago - Reply: 1 - Views: 19

Using word wildcards to find unaccepted changes

4 months ago - Reply: 1 - Views: 45

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re