htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 2: htmlArea 2 & 3 archive (read only): htmlArea v2.0:
MOD: Word cleanup function


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


redspider
User

Jan 16, 2003, 4:28 PM

Post #1 of 20 (8593 views)
Shortcut
MOD: Word cleanup function Can't Post

Hi all,

In this post i paste the code of the wordcleaner i use in my editor.

Original the function is the work of Goudinov who made it for version 1.x
Recently i add some more cleanup tags for snooper. Now you can past word documents into HtmlArea and cleanup al the extra MS-Word Code with one push at the buttom

Installation procedure:

add the buttom into the toolbaar list and the buttom list.

this.toolbar = [
['word'],

this.btnList = {
"word": ['word', 'Cleanup MS-WORD tags" ', 'editor_action(this.id)', 'ed_word.gif'],

Add the code for the buttom (in the area of the custom buttoms)


// WME: MS-Word clean-up (begin)
else if (cmdID == 'word') {
var oTags = editdoc.all.tags("SPAN");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
oTags.outerHTML = oTags.innerHTML;
}
}
oTags = editdoc.all.tags("FONT");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
oTags.outerHTML = oTags.innerHTML;
}
}
oTags = editdoc.all.tags("P");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags);
}
}
oTags = editdoc.all.tags("H1");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags);
}
}
oTags = editdoc.all.tags("H2");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags);
}
}
oTags = editdoc.all.tags("H3");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags);
}
}
oTags = editdoc.all.tags("H4");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags);
}
}
oTags = editdoc.all.tags("OL");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags);
}
}
oTags = editdoc.all.tags("UL");
if (oTags != null) {
for (var i = oTags.length - 1; i >= 0; i--) {
cleanEmptyTag(oTags); }
}
}
// WME: MS-Word clean-up (end)


Add the cleanup function


// WME: MS-Word clean-up (begin)
/* ---------------------------------------------------------------------- *\
Function : MS-Word clean-up
\* ---------------------------------------------------------------------- */

function cleanEmptyTag(oElem) {
if (oElem.hasChildNodes) {
var tmp = oElem
for (var k = tmp.children.length; k >= 0; k--) {
if (tmp.children[k] != null) {
cleanEmptyTag(tmp.children[k]);
}
}
}
var oAttribs = oElem.attributes;
if (oAttribs != null) {
for (var j = oAttribs.length - 1; j >=0; j--) {
var oAttrib = oAttribs[j];
if (oAttrib.nodeValue != null) {
oAttribs.removeNamedItem('class')
}
}
}
oElem.style.cssText = '';
if (oElem.innerHTML == '' || oElem.innerHTML == ' ') {
oElem.outerHTML = ''; }
}
function cleanTable(oElem) {
oElem.style.cssText = '';
var oAttribs = oElem.attributes;
if (oAttribs != null) {
for (var j = oAttribs.length - 1; j >=0; j--) {
var oAttrib = oAttribs[j];
if (oAttrib.nodeValue != null) {
oAttribs.removeNamedItem('class')
}
}
}
var oTR = oElem.rows;
if (oTR != null) {
for (var r = oTR.length - 1; r >= 0; r--) {
oTR[r].style.cssText = '';
}
}
var oTD = oElem.cells;
if (oTD != null) {
for (var t = oTD.length - 1; t >= 0; t--) {
oTD[t].style.cssText = '';
}
}
}
// WME: MS-Word clean-up (end)



I try to post my JS file tomorow at this post.
greetz

Redspider
Belgium
http://www.tielt.be
Attachments: ed_word.gif (0.13 KB)


ikalair
New User

Feb 24, 2003, 3:55 PM

Post #2 of 20 (8305 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

Hi Redspider

I've tried implementing your code, but nothing seems to happen when I hit the "Clean MS-WORD tags" button. Would be possible for you to post your .js file? I'll attach mine, maybe you can help spot my error.

thx.
Attachments: editor.js (49.2 KB)


redspider
User

Feb 24, 2003, 4:25 PM

Post #3 of 20 (8296 views)
Shortcut
Re: [ikalair] MOD: Word cleanup function [In reply to] Can't Post

Going to look at it tomorrow (going to sleep now)

Download and see my version on http://www.tielt.be/testzone/example.asp

See you, hear you
greetz

Redspider
Belgium
http://www.tielt.be


redspider
User

Feb 25, 2003, 2:24 AM

Post #4 of 20 (8265 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

ikalair,

In attach your editor.js with working Word-cleaner.

Don't ask me what was wrong, i just paste the button part from my editor in yours and it was working.

I try to compare the my post version with the version on my server i my lunch break.
greetz

Redspider
Belgium
http://www.tielt.be
Attachments: editor.js (49.7 KB)


sticks
Novice

Feb 25, 2003, 11:24 AM

Post #5 of 20 (8209 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

Just wanted to say thanks for the utility. This is going to save me hours with how I am using htmlArea.

Sticks


redspider
User

Feb 25, 2003, 2:10 PM

Post #6 of 20 (8201 views)
Shortcut
Re: [sticks] MOD: Word cleanup function [In reply to] Can't Post

Thanks sticks Smile.... but you don't know how many hours Htmlare saves me Wink
greetz

Redspider
Belgium
http://www.tielt.be


antikor
New User

Mar 14, 2003, 7:54 AM

Post #7 of 20 (7998 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

I've integrated your script to my editor script but when I clique on the button I've got the following error : "'style' has a null value or is not an object". I am not a king in javascript, do u have any idea which can help me ?

Thanks

Xavier


phase
Novice

Mar 15, 2003, 10:18 AM

Post #8 of 20 (7947 views)
Shortcut
Re: [antikor] MOD: Word cleanup function [In reply to] Can't Post

hi, got the same problem - and i'm also not a king ;-)


--

aha! now i took the js-file from redspider and copied the word-part and pasted in my - it works fine now!

thnx redspider!


(This post was edited by phase on Mar 15, 2003, 10:26 AM)


antikor
New User

Mar 17, 2003, 3:52 AM

Post #9 of 20 (7882 views)
Shortcut
Re: [phase] MOD: Word cleanup function [In reply to] Can't Post

Yallaaa ! Now it works thanks for the advice !

I've got an other question for the JS master .... Is there a way to lauch the filter when the user paste its text and no only when the user click on a button ?



THanks Xavier


ElPaso
Novice

Mar 31, 2003, 12:37 AM

Post #10 of 20 (7628 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

hi redspider!

very great feature! and it works... but:
strange - when doing the following - the whole internet explorer crashes:

1.) have some text in htmlarea - click the word cleaner button --> works
2.) add some linebreaks (hit enter) - click the word cleaner again --> ie crashes!

this is for ie 6.0 sp1 in w2k & winxp...

have you seen that before??
any help would be very apreciated!

thanx to interactive for that great tool!!!!!!!!!
bye
El.


redspider
User

Apr 2, 2003, 12:34 AM

Post #11 of 20 (7561 views)
Shortcut
Re: [ElPaso] MOD: Word cleanup function [In reply to] Can't Post

Hi ElPaso,

Yes i've seen it (last week) Unsure

At this moment I don't have the time to look at it Unsure.
After 18 mai I have some free time to get back concentrate on my HtmlArea project.

Sorry
greetz

Redspider
Belgium
http://www.tielt.be


ElPaso
Novice

Apr 2, 2003, 12:44 PM

Post #12 of 20 (7530 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

hi!

thanks alot for the reply - i'll use it anyway - it happens only in very strange situations, but it's a great help for keeping the code small... (and if ie crashes... well that can happen all the time - i think users won't even notice that it was htmlarea Cool)

i'll come back to see if you found the problem - i would have a look, but i'm more a vb guy - java is absolutely not my thing...

bye - and thanx again!
El.
Vienna/Austria


mbourque
Novice

Apr 4, 2003, 9:20 AM

Post #13 of 20 (7440 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

Red spider,

I must thank for for this great mod. In my opionion, this is the most important mod to have been made to HTML area (right up there with your image uploader). It works great.


(This post was edited by mbourque on Apr 4, 2003, 9:22 AM)


kuco
New User

May 29, 2003, 5:57 AM

Post #14 of 20 (7003 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

Found a bug in cleanEmptyTag

This wasnt a IE 5.5 compatible

<code>
function cleanEmptyTag(oElem) {
if (oElem.hasChildNodes) {
var tmp = oElem;
for (var k = tmp.children.length; k >= 0; k--) {
if (tmp.children[k] != null) {
cleanEmptyTag(tmp.children[k]);
}
}
}

var oAttribs = oElem.attributes;
if (oAttribs != null) {
for (var j = oAttribs.length - 1; j >=0; j--) {
var oAttrib = oAttribs[j];
if (oAttrib.nodeName != 'class') {
continue;
}

if (oAttrib.nodeValue == null) {
continue;
}

if (oAttrib.nodeValue.substring(0,3) == 'Mso') {
//oElem.attributes[j].nodeValue = '';
oElem.removeAttribute('className');
//oAttribs.removeNamedItem('class');
}
}
}

oElem.style.cssText = '';
if (oElem.innerHTML == '' || oElem.innerHTML == '&nbsp;') {
oElem.outerHTML = '';
}
}
</code>



sry for indents


Luis
Veteran

May 29, 2003, 1:57 PM

Post #15 of 20 (6984 views)
Shortcut
Re: [kuco] MOD: Word cleanup function [In reply to] Can't Post

Hi Kuko:

This is not a bug but the way as MSWord renders HTML. It has nothing to do either with HTMLArea or IE Versions.

The code you are posting doesn't prevent the indention of being cleared and does a similar work to the one achieved with the original mod. (At least in my end, using Word 9 from Office 2000 Premium)

The way as indention is rendered by my Word version is in style="Margin:..., inside a P tag.

<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in">

class= MsoNormal has nothing to do with indention.

The only way I can prevent indention of being cleared in one or the other mods, is commenting out the line

oTags = editdoc.all.tags("P"); if (oTags != null) {for (var i = oTags.length - 1; i >= 0; i--) {cleanEmptyTag(oTags);}}


in the other part of the function. Of Course, The P tag will be untouched and will keep all sort of MS code.


Don't give up!!
http://webstationone.com/test/htmlarea


blake
Novice

Jun 1, 2003, 5:03 AM

Post #16 of 20 (6934 views)
Shortcut
Re: [redspider] MOD: Word cleanup function [In reply to] Can't Post

Hiya.

First of all, thanks for this great function!

Secondly, how would one go about adding custom tags, e.g. a Word 2002 smart tag...like

Code
 <st1:place>...</st1:place>

I figured out how to add custom tags, but that one eludes me - it just doesn't work. Does this have something to do with the colon? How would one go about modifying the cleanup function to strip these tags too?

Thanks in advance,

-Blake-


Luis
Veteran

Jun 1, 2003, 4:16 PM

Post #17 of 20 (6917 views)
Shortcut
Re: [blake] MOD: Word cleanup function [In reply to] Can't Post

Hi Blake:

Do you have the function cleanHTML(unclean) enabled?

If you do, add this lines at the top of the function:

unclean = unclean.replace(/<\\?\??xml[^>]>/gi, "");
unclean = unclean.replace(/<\/?\w+:[^>]*>/gi, "");

If you don't, go to http://webstationone.com/test/htmlarea/ and download my editor.

Make a search for cleanHTML(unclean) in my editor.js to find out where the function is being applied and make the changes to your editor.


Don't give up!!
http://webstationone.com/test/htmlarea


blake
Novice

Jun 1, 2003, 5:27 PM

Post #18 of 20 (6909 views)
Shortcut
Re: [Luis] MOD: Word cleanup function [In reply to] Can't Post

Thanks, Luis - I will give it a try. (:


zunic
New User

Jul 24, 2003, 5:13 PM

Post #19 of 20 (6537 views)
Shortcut
Re: MOD: Word cleanup function [In reply to] Can't Post

Hi all,

I just past a lot of time on the forum to solve some of my problems. I solved a lot, thank you very much!!

Two problems remind :

1) As, ANTIKOR asked, is there a way to launch the Word cleanup function when the user paste its text?

2) I have a weird problem when pasting special characters like these one : (Em Dash) and (French apostrophe). When I submit the textarea with these characters, the page is reloaded and not submited. Weird!!

Thank you in advance.

Pascal


Luis
Veteran

Jul 24, 2003, 6:14 PM

Post #20 of 20 (6533 views)
Shortcut
Re: [zunic] MOD: Word cleanup function [In reply to] Can't Post

Hi Zunic:

Regarding Word Cleaner on paste, look at this other post:
http://www.interactivetools.com/forum/gforum.cgi?post=10572

For the French characters, I think it has nothing to do with HTMLArea. I use to post bunch of documents in French everyday and the editor works perfectly. My guess is that it has something to do with your submission script.


Don't give up!!
http://webstationone.com/test/htmlarea


(This post was edited by Luis on Jul 24, 2003, 6:14 PM)

 
 
 


Search for (options)