&nbsp causing problems in flash

Last post 04-29-2006, 5:31 PM by pogier. 1 replies.
Sort Posts: Previous Next
  •  04-29-2006, 7:04 AM 18599

    &nbsp causing problems in flash

    Hi there,
    I need to remove all the &nbsp when i clean code. The problem comes in Flash as it doesn't render this and then decides that it is a new variable.
     
    Is there a simple piece of code i can include in one of the cute editor files so it cleans it?
     
    Thanks
     
    Paul Ogier
  •  04-29-2006, 5:31 PM 18607 in reply to 18599

    Re: &nbsp causing problems in flash

    Well i solved it!!! So everyone stop panicking!!!
     
    I thought that i would share the fix in case anyone would like it.
     
    under the "CuteEditor_Files" folder there is a file "WinIE.js" well in my file at around line 803 there was this:
     
    function cleanCode(EditorID) {
     var editor = document.getElementById(EditorID);
     editor.innerHTML = cleantool(editor.innerHTML);;
    // alert("MS Word Formatting Removed");
    }
    function cleantool(h)
    {
     h = h.replace(/<o:[pP]>&nbsp;<\/o:[pP]>/g, ""); // Remove all instances of <o:p></o:p>
        h = h.replace(/o:/g, ""); // delete all o: prefixes
        h = h.replace(/<st1:.*?>/g, ""); // delete all smarttags
        h = h.replace(/<(\/)?strong>/ig, '<$1B> '); //replaces <STRONG> with <B>
     h = h.replace(/<(\/)?em>/ig, '<$1I> '); //replaces <EM> with <I>
     h = h.replace(/<P class=[^>]*>/gi, '<P>');
     h = h.replace(/<]>/gi" href_cetemp="file://\\?\??xml[^>]>/gi">\\?\??xml[^>]>/gi, "");
     h = h.replace(/<\/?\w+:[^>]*>/gi, "");
     h = h.replace(/<SPAN[^>]*>/gi, '');
     h = h.replace(/<\/SPAN>/gi, '');
     h = h.replace(/<TBODY>/gi, '');
     h = h.replace(/<\/TBODY>/gi, '');
     h = h.replace(/<T/gi, '\n<T');
     h = h.replace(/<TD>\n/gi, '<TD>');
     h = h.replace(/<\/TR>/gi, '\n<\/TR>');
     h = h.replace(/<\/TR>\n/gi, '<\/TR>'); 
     return h;
    }
    function removeword(h)
    {
     h = h.replace(/<\?xml[^>]*>/ig, "");
     h = h.replace(/<\/?[a-z]+:[^>]*>/ig, "");
     h = h.replace(new RegExp("(<[^>]+) class=[^ |^>]*([^>]*>)", "ig"), "$1 $2");
     h = h.replace(/(<[^>]+) style="[^"]*"([^>]*>)/ig, "$1 $2");
     h = h.replace(/<span[^>]*><\/span[^>]*>/ig, "");
     h = h.replace(/<span[^>]*><\/span[^>]*>/ig, "");
     h = h.replace(/<span><span>/ig, "<span>");
     h = h.replace(/<\/span><\/span>/ig, "</span>");
     return h;
     
    but i added this to remove "&nbsp;"
     
        h = h.replace(/&nbsp;/g, "");
     
    under "function cleantool(h)" and "function removeword(h)" cause i can.
     
    but then i found that "&amp" and "&quot;"also caused problems in flash because of the "&", it thinks it's another variable, so i stuck in this line in both places as well:
     
     h = h.replace(/&amp;/g, "and"); 
     h = h.replace(/&quot;/g, "'");
     
    But then i just got carried away, and now the code that was, is now:
     
    function cleanCode(EditorID) {
     var editor = document.getElementById(EditorID);
     editor.innerHTML = cleantool(editor.innerHTML);;
    // alert("MS Word Formatting Removed");
    }
    function cleantool(h)
    {
     h = h.replace(/<\?xml[^>]*>/ig, "");
     h = h.replace(/<\/?[a-z]+:[^>]*>/ig, "");
     h = h.replace(new RegExp("(<[^>]+) class=[^ |^>]*([^>]*>)", "ig"), "$1 $2"); 
     h = h.replace(/(<[^>]+) style="[^"]*"([^>]*>)/ig, "$1 $2");      
     h = h.replace(/<span[^>]*><\/span[^>]*>/ig, "");
     h = h.replace(/<span[^>]*><\/span[^>]*>/ig, "");
     h = h.replace(/<span><span>/ig, "<span>");
     h = h.replace(/<\/span><\/span>/ig, "</span>");
     h = h.replace(/<o:[pP]>&nbsp;<\/o:[pP]>/g, "");
        h = h.replace(/o:/g, "");
        h = h.replace(/<st1:.*?>/g, "");
        h = h.replace(/<(\/)?strong>/ig, '<$1B> ');
     h = h.replace(/<(\/)?em>/ig, '<$1I> ');
     h = h.replace(/<P class=[^>]*>/gi, '<P>');
     h = h.replace(/<]>/gi" href_cetemp="file://\\?\??xml[^>]>/gi">\\?\??xml[^>]>/gi, "");
     h = h.replace(/<\/?\w+:[^>]*>/gi, "");
     h = h.replace(/<SPAN[^>]*>/gi, '');
     h = h.replace(/<\/SPAN>/gi, '');
     h = h.replace(/<TBODY>/gi, '');
     h = h.replace(/<\/TBODY>/gi, '');
     h = h.replace(/<T/gi, '\n<T');
     h = h.replace(/<TD>\n/gi, '<TD>');
     h = h.replace(/<\/TR>/gi, '\n<\/TR>');
     h = h.replace(/<\/TR>\n/gi, '<\/TR>'); 
        h = h.replace(/&nbsp;/g, "");  
     h = h.replace(/&amp;/g, "and"); 
     h = h.replace(/&quot;/g, "'");
     h = h.replace(/<(\/)?H1>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H2>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H3>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H4>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H5>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H6>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H7>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H8>/ig, '<$1p> ');
     h = h.replace(/<(\/)?SPAN>/ig, "");
     h = h.replace(/<LOCK.*?>/g, "");
     h = h.replace(/<(\/)?LOCK>/ig, "");
     h = h.replace(/<EXTRUSION.*?>/g, "");
     h = h.replace(/<(\/)?EXTRUSION>/ig, "");  
     return h;
    }
    function removeword(h)
    {
     h = h.replace(/<\?xml[^>]*>/ig, "");
     h = h.replace(/<\/?[a-z]+:[^>]*>/ig, "");
     h = h.replace(new RegExp("(<[^>]+) class=[^ |^>]*([^>]*>)", "ig"), "$1 $2"); 
     h = h.replace(/(<[^>]+) style="[^"]*"([^>]*>)/ig, "$1 $2");      
     h = h.replace(/<span[^>]*><\/span[^>]*>/ig, "");
     h = h.replace(/<span[^>]*><\/span[^>]*>/ig, "");
     h = h.replace(/<span><span>/ig, "<span>");
     h = h.replace(/<\/span><\/span>/ig, "</span>");
     h = h.replace(/<o:[pP]>&nbsp;<\/o:[pP]>/g, "");
        h = h.replace(/o:/g, "");
        h = h.replace(/<st1:.*?>/g, "");
        h = h.replace(/<(\/)?strong>/ig, '<$1B> ');
     h = h.replace(/<(\/)?em>/ig, '<$1I> ');
     h = h.replace(/<P class=[^>]*>/gi, '<P>');
     h = h.replace(/<]>/gi" href_cetemp="file://\\?\??xml[^>]>/gi">\\?\??xml[^>]>/gi, "");
     h = h.replace(/<\/?\w+:[^>]*>/gi, "");
     h = h.replace(/<SPAN[^>]*>/gi, '');
     h = h.replace(/<\/SPAN>/gi, '');
     h = h.replace(/<TBODY>/gi, '');
     h = h.replace(/<\/TBODY>/gi, '');
     h = h.replace(/<T/gi, '\n<T');
     h = h.replace(/<TD>\n/gi, '<TD>');
     h = h.replace(/<\/TR>/gi, '\n<\/TR>');
     h = h.replace(/<\/TR>\n/gi, '<\/TR>'); 
        h = h.replace(/&nbsp;/g, "");  
     h = h.replace(/&amp;/g, "and"); 
     h = h.replace(/&quot;/g, "'");
     h = h.replace(/<(\/)?H1>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H2>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H3>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H4>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H5>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H6>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H7>/ig, '<$1p> ');
     h = h.replace(/<(\/)?H8>/ig, '<$1p> ');
     h = h.replace(/<(\/)?SPAN>/ig, "");
     h = h.replace(/<LOCK.*?>/g, "");
     h = h.replace(/<(\/)?LOCK>/ig, "");
     h = h.replace(/<EXTRUSION.*?>/g, "");
     h = h.replace(/<(\/)?EXTRUSION>/ig, "");  
     return h;
    }
     
    I just found that is was an extra click to clean the code if i paste from Word. so now it does everything in one.
     
    On a personal note how much F&%^ing code does word actually stick in??
View as RSS news feed in XML