htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
v3 Word Cleaner & questions


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.

 


weeezl
Novice

Aug 19, 2003, 12:15 AM

Post #1 of 24 (12814 views)
Shortcut
v3 Word Cleaner & questions Can't Post

Hey all,

I've just finished my cross-browser first pass of a Word Cleaner for htmlArea 3.0! It can clean content pasted from Word Documents on paste or through a button. It's pretty clean right now, removing all excess Word garbage but keeping the basic formatting.

I have a couple of questions about how best to distribute this. I guess this is a question for Mishoo. Is there a process for adding features to htmlArea? I would like to include this as a feature in the final code for v3 if possible.

Also, it might be nice to separate the forums for v3 addons and v2 addons since there seems to be some confusion about which addons work with which version.

Thanks!

-weez Crazy


ezagent
Novice

Aug 25, 2003, 6:57 PM

Post #2 of 24 (12756 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

Can you upload your module to the forum? Also, I'm curious about usage. To use the word cleaner does one view the source of a web page created in Word, copy the source and paste it into htmlarea? Is there any explanation of usage?


Custa
Novice

Sep 1, 2003, 3:29 AM

Post #3 of 24 (12685 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

As I think this is one of the most important functions of a CMS (coz which of those folk out there does not write all their stuff in Word) of any sort. Is there any news as to when this may be released upon us eager people. Is it possible to send on to those wanting to test it? Current project could currently benefit from a word importer.

Thanx for your time guys.


(This post was edited by Custa on Sep 8, 2003, 12:50 AM)


Tonio
Novice

Sep 1, 2003, 4:44 AM

Post #4 of 24 (12676 views)
Shortcut
Re: [Custa] v3 Word Cleaner & questions [In reply to] Can't Post

Hello,

I'm also very interested by this functionality... Could you please upload your js file on the forum, Weeezl ?!? It would very sympathetic from you !!!

NB : I'm agree Weeezl to separate V2 and v3 addons!!!! It should be so more clear !!!

Bye,

TonioBlushBlushWink


weeezl
Novice

Sep 13, 2003, 2:01 PM

Post #5 of 24 (12553 views)
Shortcut
Re: [Tonio] v3 Word Cleaner & questions [In reply to] Can't Post

arrr...

ok.. Here's the prelim Word Cleaner Code. I am going to send this to Mishoo for some reworking but for all of you guys out there jonesing for this code, here it is:

First, you need to add this piece of code to the existing code. Search for the first line (case "showhelp") and then add the pastespecial below it


Code
 case "showhelp" : window.open("reference.html", "ha_help"); break; 
case "pastespecial" : this._pasteSpecial(); break;

Next, add a new keycode for control V. Again search for the previous line and add the code below.


Code
 case 'j': cmd = "justifyfull"; break; 
case 'v': this.execCommand("pasteSpecial"); break;



Then, add this code somewhere in the editor. I put it right above the "Category: Event Handlers" section


Code
  

// Called when the user Pastes from Ctrl-V;

HTMLArea.prototype._pasteSpecial = function() {

var editor = this; // for nested functions

editor.unPasteSpecial = function () {editor._unPasteSpecial()};

HTMLArea._addEvent(editor._doc, "keyup",editor.unPasteSpecial);

};

// Called on Ctrl-V keyup;

HTMLArea.prototype._unPasteSpecial = function() {

var editor = this;

HTMLArea._removeEvent(editor._doc, "keyup",editor.unPasteSpecial);

editor._wordClean();

};

// Word Clean Function;

HTMLArea.prototype._wordClean = function() {

var editor = this;

var wordData = editor._doc.body.innerHTML;

if (wordData.indexOf('class=Mso')>=0){

// make one line

wordData = wordData.replace(/\r\n/g, '');

wordData = wordData.replace(/\n/g, '');

wordData = wordData.replace(/\r/g, '');

wordData = wordData.replace(/\&nbsp\;/g,'');

// keep tags, strip attributes

wordData = wordData.replace(/ class=[^\s|>]*/gi,'');

//wordData = wordData.replace(/<p [^>]*TEXT-ALIGN: justify[^>]*>/gi,'<p align="justify">');

wordData = wordData.replace(/ style=\"[^>]*\"/gi,'');

//clean up tags

wordData = wordData.replace(/<b [^>]*>/gi,'<b>');

wordData = wordData.replace(/<i [^>]*>/gi,'<i>');

wordData = wordData.replace(/<li [^>]*>/gi,'<li>');

wordData = wordData.replace(/<ul [^>]*>/gi,'<ul>');

// replace outdated tags

wordData = wordData.replace(/<b>/gi,'<strong>');

wordData = wordData.replace(/<\/b>/gi,'</strong>');

wordData = wordData.replace(/<i>/gi,'<em>');

wordData = wordData.replace(/<\/i>/gi,'</em>');

// kill unwanted tags

wordData = wordData.replace(/<\?xml:[^>]*>/g, ''); // Word xml

wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags

wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff

wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting

wordData = wordData.replace(/<\/?span[^>]*>/gi,'');

wordData = wordData.replace(/<\/?div[^>]*>/gi,'');

//remove empty tags

wordData = wordData.replace(/<strong><\/strong>/gi,'');

wordData = wordData.replace(/<P[^>]*><\/P>/gi,'');



editor._doc.body.innerHTML = wordData;

editor.updateToolbar();

}



}



Now code pasted from Word should clean. I am going to develop this more but this is the forst pass and should work fairly well.

-weeezl


Tonio
Novice

Sep 26, 2003, 10:45 AM

Post #6 of 24 (12403 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

Hi !!!

First, sorry to not have replied to you earlier, Weeezl !!!! Smile A lot of work !!!

Thank you very much for your code... I tested it on my application and it works perfectly !!!
NB : I had yet to ajust it to my specifications... normal !!! Wink

Anyway.... it's a great great job !!! Still thanks !!!

Bye !

Tonio


Slump
New User

Oct 1, 2003, 9:09 AM

Post #7 of 24 (12316 views)
Shortcut
Re: [Tonio] v3 Word Cleaner & questions [In reply to] Can't Post

Hi, i'm a new user !!!!

Very good code... but i had to do some modifications, because my version is 2.03.

But i don't know what i must to do for control V fonction ??????

Thanx for your help !!!!

Sorry for my english (i'm french) !!!

My code :


Code
    //  
// CUSTOM BUTTONS START HERE
//// Word
else if (cmdID == 'word') { // insert some text from a popup window
var filepath, parsetype;
var arr = null;
arr = showModalDialog(_editor_url + "word2.html",0,"dialogWidth:350px; dialogHeight:100px; status:0; help:0;");



if (arr != null) {
filepath = arr["filepath"];
parsetype = parseInt(arr["parsetype"]);
var wordapp = new ActiveXObject("Word.Application");
wordapp.Visible=false;
wordapp.Documents.Open(filepath, false, true, false);
var worddoc = wordapp.Documents(filepath);
worddoc.Range().Copy();
editdoc.execCommand("Paste");
wordapp.quit();
}

var wordData = editdoc.body.innerHTML;
if (wordData.indexOf('class=Mso')>=0) {
wordData = wordData.replace(/\n/g, '');
wordData = wordData.replace(/\r/g, '');
wordData = wordData.replace(/\&nbsp\;/g,''); // keep tags, strip attributes
wordData = wordData.replace(/ class=[^\s|>]*/gi,'');
wordData = wordData.replace(/ style=\"[^>]*\"/gi,''); //clean up tags
wordData = wordData.replace(/<li [^>]*>/gi,'<li>');
wordData = wordData.replace(/<ul [^>]*>/gi,'<ul>'); // replace outdated tags
wordData = wordData.replace(/<ol [^>]*>/gi,'<ul>');
wordData = wordData.replace(/<\/ol>/gi,'</ul>');
wordData = wordData.replace(/<h[^>]*>/gi,'<strong>');
wordData = wordData.replace(/<\/h[^>]*>/gi,'</strong><br><br>');
wordData = wordData.replace(/<b [^>]*>/gi,'<b>');
wordData = wordData.replace(/<i [^>]*>/gi,'<i>');
wordData = wordData.replace(/<b>/gi,'<strong>');
wordData = wordData.replace(/<\/b>/gi,'</strong>');
wordData = wordData.replace(/<i>/gi,'<em>');
wordData = wordData.replace(/<\/i>/gi,'</em>'); // kill unwanted tags
wordData = wordData.replace(/<\?xml:[^>]*>/g, ''); // Word xml
wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
wordData = wordData.replace(/<\/?span[^>]*>/gi,'');
wordData = wordData.replace(/<\/?div[^>]*>/gi,''); //remove empty tags
wordData = wordData.replace(/<p[^>]*><\/p>/gi,'');
wordData = wordData.replace(/<p>/gi,'');
wordData = wordData.replace(/<\/p>/gi,'<br>');
//wordData = wordData.replace(/<br>/gi,"<br />");
editdoc.body.innerHTML = wordData;
}
}

//
// END OF CUSTOM BUTTONS
//



polel129
New User

Oct 3, 2003, 5:59 AM

Post #8 of 24 (12268 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

hi weeezl,

how can i call this function when I click on the paste icon?

thanks


ephemeros
Novice

Nov 11, 2003, 6:44 PM

Post #9 of 24 (11890 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

Great script weeezl! thanks

Took the liberty to bump and improve (I hope) Tongue

Based on htmlarea latest cvs (11/11/03)..

Code
// Called when the user Pastes from Ctrl-V; 
HTMLArea.prototype._pasteSpecial = function() {
var editor = this; // for nested functions
editor.unPasteSpecial = function () {editor._unPasteSpecial()};
HTMLArea._addEvent(editor._doc, "keyup",editor.unPasteSpecial);
};

// Called on Ctrl-V keyup;
HTMLArea.prototype._unPasteSpecial = function() {
var editor = this;
HTMLArea._removeEvent(editor._doc, "keyup",editor.unPasteSpecial);
editor._wordClean();
};

// Word Clean Function;
HTMLArea.prototype._wordClean = function() {
var editor = this;
var wordData = this.getInnerHTML();
if (wordData.indexOf('class="Mso')>=0){
// make one line
wordData = wordData.replace(/\r\n/g, ' ');
wordData = wordData.replace(/\n/g, ' ');
wordData = wordData.replace(/\r/g, ' ');
wordData = wordData.replace(/\&nbsp\;/g,' ');
// keep tags, strip attributes
wordData = wordData.replace(/ class=[^\s|>]*/gi,'');
//wordData = wordData.replace(/<p [^>]*TEXT-ALIGN: justify[^>]*>/gi,'<p align="justify">');
wordData = wordData.replace(/ style=\"[^>]*\"/gi,'');
//clean up tags
wordData = wordData.replace(/<b [^>]*>/gi,'<b>');
wordData = wordData.replace(/<i [^>]*>/gi,'<i>');
wordData = wordData.replace(/<li [^>]*>/gi,'<li>');
wordData = wordData.replace(/<ul [^>]*>/gi,'<ul>');
// replace outdated tags
wordData = wordData.replace(/<b>/gi,'<strong>');
wordData = wordData.replace(/<\/b>/gi,'</strong>');
wordData = wordData.replace(/<i>/gi,'<em>');
wordData = wordData.replace(/<\/i>/gi,'</em>');
// kill unwanted tags
wordData = wordData.replace(/<\?xml:[^>]*>/g, ''); // Word xml
wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
wordData = wordData.replace(/<\/?span[^>]*>/gi,'');
wordData = wordData.replace(/<\/?div[^>]*>/gi,'');
//remove empty tags
wordData = wordData.replace(/<strong><\/strong>/gi,'');
wordData = wordData.replace(/<P[^>]*><\/P>/gi,'');
//remove comments and extra spaces
wordData = wordData.replace(/<!--[^>]*>/gi,'');
wordData = wordData.replace(/>[ ]*</g,'><');

this.setHTML(wordData);
this.updateToolbar();
}
}


Greetz
-eph


(This post was edited by ephemeros on Nov 11, 2003, 6:45 PM)


riotx
New User

Nov 14, 2003, 2:25 AM

Post #10 of 24 (11819 views)
Shortcut
Re: [ephemeros] v3 Word Cleaner & questions [In reply to] Can't Post

very good code ... but only works for a control-v paste... how can I get it to work with right click paste, or the paste Icon?

cheers


ephemeros
Novice

Nov 14, 2003, 1:45 PM

Post #11 of 24 (11792 views)
Shortcut
Re: [riotx] v3 Word Cleaner & questions [In reply to] Can't Post

Just took WordCleaner to another level. Smile I added some lines that are in fact beyond the scope of simple Word cleaning, but are essential for htmlArea compatibility (changing <b>,<i>,<u>-tags to their css equivalent) and then some more. Also works now under Gecko browsers!


Code
// Word Clean Function; 
HTMLArea.prototype._wordClean = function() {
var editor = this;
var wordData = this.getInnerHTML();
// make one line
wordData = wordData.replace(/[\r\n]+|\&nbsp\;/g, ' ');
if ((wordData.indexOf('class=Mso')>=0) | (wordData.indexOf('class="Mso')>=0)){
// keep tags, strip attributes
wordData = wordData.replace(/ class=[^\s|>]*/gi,'');
wordData = wordData.replace(/ style=\"[^>]*\"/gi,'');
wordData = wordData.replace(/<(b|i|li|ul) [^>]*>/gi,"<$1>");
//wordData = wordData.replace(/<p [^>]*TEXT-ALIGN: justify[^>]*>/gi,'<p align="justify">');
// kill unwanted tags
wordData = wordData.replace(/<\?xml:[^>]*>/g, ''); // Word xml
wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
wordData = wordData.replace(/<\/?(span|div)[^>]*>/gi,'');
wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
wordData = wordData.replace(/<!--[^>]*>/gi,''); // Word comments
// clean up html
wordData = wordData.replace(/ [ ]*/g, ' ');
}
// ensure htmlArea compatibility
wordData = wordData.replace(/<b>|<strong>/gi,'<span style="font-weight: bold;">');
wordData = wordData.replace(/<i>|<em>/gi,'<span style="font-style: italic;">');
wordData = wordData.replace(/<u>/gi,'<span style="text-decoration: underline;">');
wordData = wordData.replace(/<\/([biu]|strong|em)>/gi,'</span>');
// remove empty tags
wordData = wordData.replace(/>[ ]*</g,'><');
wordData = wordData.replace(/<strong><\/strong>|<em><\/em>|<h[1-6]><\/h[1-6]>/gi,'');
wordData = wordData.replace(/<p[^>]*><\/p>/gi,'');
// format
wordData = wordData.replace(/<\/(p|br[ \/]*|h[1-6]|table|tr|ol|ul|li)>/gi,"<\/$1>\n");
// open links in new windows
wordData = wordData.replace(/<a /gi,'<a target="_blank" '); // Disable if you already have targets assigned or don't want to!

this.setHTML(wordData);
this.updateToolbar();
}


To answer your question riotx:
change the following line to the italic version:

Code
		paste: [ "Paste from clipboard", "ed_paste.gif", false, cut_copy_paste ], 
paste: [ "Paste from clipboard", "ed_paste.gif", false, function(e) {e.execCommand("paste"); e._wordClean();} ],

I dunno about right-click though Unsure

-eph


weeezl
Novice

Nov 15, 2003, 10:19 AM

Post #12 of 24 (11764 views)
Shortcut
Re: [ephemeros] v3 Word Cleaner & questions [In reply to] Can't Post

Thanks for the code cleanup eph...

One note for people that may not know: There is a difference in the way the editor works in Explorer and Gecko. Gecko uses span tags for bold italic etc while Explorer uses the simpler <b>,<i>. I actually prefer the Explorer method (less code). Just wanted people to know. The code should still work cross-browser regarless of the format you choose to implement.

Great job on cleanup though! I'm now trying to see if I can program something to preserve single spacing within formatted blocks of text. Glad this code is progressing.

-weeezl


ephemeros
Novice

Nov 15, 2003, 6:23 PM

Post #13 of 24 (11741 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

And we don't stop Tongue
Nice you noticed the Explorer-Gecko difference Smile What you say isn't completely true though: the bold/italic/underline-effect is shown, but you can't edit the tags if the html isn't in the correct form.. which means that now output is generated depending on which browser you use (I hated doing this Unsure)
Further tweaked open-links-in-new-window (not when already target assigned or on mailto:) You can use this form of replacing to keep code-blocks, ... formatted

Here comes:

Code
// Word Clean Function v1.0.3; 
HTMLArea.prototype._wordClean = function() {
var editor = this;
var wordData = this.getInnerHTML();
// make one line
wordData = wordData.replace(/[\r\n]+|\&nbsp\;/g, ' ');
if ((wordData.indexOf('class=Mso')>=0) | (wordData.indexOf('class="Mso')>=0)){
// kill unwanted tags
wordData = wordData.replace(/<\?xml:[^>]*>/g, ''); // Word xml
wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
wordData = wordData.replace(/<\/?(span|div)[^>]*>/gi,'');
wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
wordData = wordData.replace(/<!--[^>]*>/gi,''); // Word comments
// keep tags, strip attributes
wordData = wordData.replace(/ class=[^\s|>]*/gi,'');
wordData = wordData.replace(/ style=\"[^>]*\"/gi,'');
wordData = wordData.replace(/<(b|i|li|ul) [^>]*>/gi,"<$1>");
//wordData = wordData.replace(/<p [^>]*TEXT-ALIGN: justify[^>]*>/gi,'<p align="justify">');
// clean up html
wordData = wordData.replace(/ [ ]*/g, ' ');
}
// ensure htmlArea compatibility
if (HTMLArea.is_gecko) {
wordData = wordData.replace(/<b>|<strong>/gi,'<span style="font-weight: bold;">');
wordData = wordData.replace(/<i>|<em>/gi,'<span style="font-style: italic;">');
wordData = wordData.replace(/<u>/gi,'<span style="text-decoration: underline;">');
wordData = wordData.replace(/<\/([biu]|strong|em)>/gi,'</span>');
} else {
wordData = wordData.replace(/<(\/?)b>/gi,'<$1strong>');
wordData = wordData.replace(/<(\/?)i>/gi,'<$1em>');
}
// remove empty tags
wordData = wordData.replace(/>[ ]*</g,'><');
wordData = wordData.replace(/<p[^>]*><\/p>|<span[^>]*><\/span>|<strong><\/strong>|<em><\/em>|<h[1-6]><\/h[1-6]>/gi,'');
// open links in new windows
wordData = wordData.replace(/<a ([^>]*)>/gi,
function (str, p1) {
if ((str.indexOf('mailto:') >= 0) | (str.indexOf('target=') >= 0)) { return '<a ' + p1 + '>'; }
else { return '<a ' + p1 + ' target="_blank">'; }
} ); // Disable these lines if you don't want links to open in external windows
// format
wordData = wordData.replace(/<\/(p|h[1-6]|table|tr|ol|ul|li)>/gi,"<\/$1>\n");
wordData = wordData.replace(/<br[ \/]*>/gi,"<br \/>\n");

this.setHTML(wordData);
this.updateToolbar();
}


-eph


weblogger
Novice

Nov 16, 2003, 7:40 AM

Post #14 of 24 (11732 views)
Shortcut
Re: [ephemeros] v3 Word Cleaner & questions [In reply to] Can't Post

wow!
Such a nice work i alwayes had this problem i hate span tags :(Frown

but i think it will be better when there is an option for normal paste or spesial paste (becouse some times normal paste is better) so i think if you can insert a chek box or define a another button as special paste it will be better

thx for your code
sorry about my english i know a little :)
I am here 4 share my knowlage


weeezl
Novice

Nov 16, 2003, 11:26 AM

Post #15 of 24 (11726 views)
Shortcut
Re: [ephemeros] v3 Word Cleaner & questions [In reply to] Can't Post

Beautiful!

Here's an update that preserves more of the orginal formatting (alignment/indent/single spacing).


Code
 // Word Clean Function v1.0.4;   
HTMLArea.prototype._wordClean = function() {
var editor = this;
var wordData = this.getInnerHTML();
// Format data for cleanup
wordData = wordData.replace(/[\r\n]+|\&nbsp\;| [ ]*/g, ' ');
if ((wordData.indexOf('class=Mso')>=0) | (wordData.indexOf('class="Mso')>=0)){
// kill unwanted tags
wordData = wordData.replace(/<\?xml:[^>]*>/g,''); // Word xml
wordData = wordData.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
wordData = wordData.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
wordData = wordData.replace(/<\/?(span|div)[^>]*>/gi,'');
wordData = wordData.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to keep font formatting
wordData = wordData.replace(/<!--[^>]*>/gi,''); // Word comments
// preserve formatting
wordData = wordData.replace(/(<P [^>]*(MARGIN: 0in 0in 0pt 0\.5*in|margin-left: 0\.5*in)[^>]*>.*?<\/p>)/gi,'<blockquote>$1</blockquote>'); // Indent
wordData = wordData.replace(/<p [^>]*TEXT-ALIGN: ([a-z]*)[^>]*>/gi,'<p align=$1>'); // Alignment
// keep tags, strip attributes
wordData = wordData.replace(/ class=[^\s|>]*/gi,'');
wordData = wordData.replace(/ style=\"[^>]*\"/gi,'');
wordData = wordData.replace(/<(b|i|li|ul) [^>]*>/gi,"<$1>");
// remove empty tags
wordData = wordData.replace(/>[ ]*</g,'><');
wordData = wordData.replace(/<p[^>]*><\/p>/gi,'\n'); // Preserve Formatting
wordData = wordData.replace(/<span[^>]*><\/span>|<strong><\/strong>|<em><\/em>|<h[1-6]><\/h[1-6]>/gi,'');
// preserve single spacing
wordData = wordData.replace(/<\/blockquote><blockquote>/gi,''); // Extra blockquotes
wordData = wordData.replace(/(<\/p><p[^>]*>)/gi,'<br>'); // Should be <br>, not <p>
}
// ensure htmlArea compatibility
if (HTMLArea.is_gecko) {
wordData = wordData.replace(/<b>|<strong>/gi,'<span style="font-weight: bold;">');
wordData = wordData.replace(/<i>|<em>/gi,'<span style="font-style: italic;">');
wordData = wordData.replace(/<u>/gi,'<span style="text-decoration: underline;">');
wordData = wordData.replace(/<\/([biu]|strong|em)>/gi,'</span>');
} else {
wordData = wordData.replace(/<(\/?)b>/gi,'<$1strong>');
wordData = wordData.replace(/<(\/?)i>/gi,'<$1em>');
}
// open links in new windows
wordData = wordData.replace(/<a ([^>]*)>/gi,
function (str, p1) {
if ((str.indexOf('mailto:') >= 0) | (str.indexOf('target=') >= 0)) { return '<a ' + p1 + '>'; }
else { return '<a ' + p1 + ' target="_blank">'; }
} ); // Disable these lines if you don't want links to open in external windows
// format
wordData = wordData.replace(/<\/(p|h[1-6]|table|tr|ol|ul|li|blockquote)>/gi,"<\/$1>\r\n");
wordData = wordData.replace(/<br[ \/]*>/gi,"<br \/>\r\n");

this.setHTML(wordData);
this.updateToolbar();
}



(This post was edited by weeezl on Nov 17, 2003, 10:17 PM)


willi
New User

Dec 8, 2003, 8:36 AM

Post #16 of 24 (11394 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post

As I see you can handle different browsers, but how do I get this to work in gecko?
I thought gecko has no option to paste the clipboard by script (if you don't get your user to change some js scripts on their local machine) or am I wrong?
It doesn't seem to work on my Mozilla 1.5x/Win.


JSTijn
Novice

Dec 22, 2003, 9:32 AM

Post #17 of 24 (11162 views)
Shortcut
Re: [willi] v3 Word Cleaner & questions [In reply to] Can't Post

I have built an wordcleaner myself (with help from an editor named fckeditor). The trick is to give every editor an own hidden div where they store temporary data like clipboarddata.
Here is the code:

Code
 
HTMLArea.prototype.pasteword = function(){
this.TempDiv = this.createTempDiv(this._textarea+'_temp_div');
}

HTMLArea.prototype.createTempDiv = function(divName){
document.write('<div style="width:1px;height:1px;visibility:hidden;border:1px black solid;" id="'+divName+'"></div>');
return document.getElementById(divName);
}

HTMLArea.prototype.onPaste = function(){
var sHTML = this.GetClipboardHTML() ;
var re = /<\w[^>]* class="?MsoNormal"?/gi ;
if ( re.test( sHTML ) ) {
this.cleanAndPaste( sHTML ) ;
return false ;
}
return true ;
}

HTMLArea.prototype.GetClipboardHTML = function(){

oDiv = this.TempDiv;
oDiv.innerHTML = "" ;

var oTextRange = document.body.createTextRange() ;
oTextRange.moveToElementText(oDiv) ;
oTextRange.execCommand("Paste") ;
var sData = oDiv.innerHTML ;
oDiv.innerHTML = "" ;
return sData ;
}

HTMLArea.prototype.cleanAndPaste = function(html){
// Remove all SPAN tags
html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
// Remove Class attributes
html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove Style attributes
html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
// Remove Lang attributes
html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
// Remove XML elements and declarations
html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
// Remove Tags with XML namespace declarations: <o:p></o:p>
html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
// Replace the &nbsp;
html = html.replace(/&nbsp;/, " " );
// Transform <P> to <DIV>
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
html = html.replace( re, "<div$2</div>" ) ;
// Transforms all anchors to other:
//html = html.replace('="#','="other:');

this.insertHtml( html ) ;
}

HTMLArea.prototype.insertHtml = function(html){
this.insertHTML(html)
}


i commented the original code in the wordclean() function and i added this:


Code
this.onPaste();


To create the temporary div i added this in the main HTMLArea function.

Code
this.pasteword();


you can add or leave out as much as you want with regExp.


weaky
New User

Feb 21, 2004, 3:21 PM

Post #18 of 24 (10297 views)
Shortcut
Re: [JSTijn] v3 Word Cleaner & questions [In reply to] Can't Post

p.s. the above post only works in IE


JSTijn
Novice

Feb 23, 2004, 2:22 AM

Post #19 of 24 (10261 views)
Shortcut
Re: [weaky] v3 Word Cleaner & questions [In reply to] Can't Post

I will post a newer version in plugin format after some testing.

The current wordcleaner has a major problem. It cleans the text that is allready in htmlarea and not the text that is pasted.


fredp
New User

Feb 28, 2004, 11:09 AM

Post #20 of 24 (10070 views)
Shortcut
Re: [JSTijn] v3 Word Cleaner & questions [In reply to] Can't Post

Hi,

this is all of the higher interest, but whre do you find the lines in version 3 ?

case "showhelp" : window.open("reference.html", "ha_help"); break;
case "pastespecial" : this._pasteSpecial(); break;


Thanks,



Fred


bsutton
Novice

Mar 2, 2004, 5:52 PM

Post #21 of 24 (9964 views)
Shortcut
Re: [JSTijn] v3 Word Cleaner & questions [In reply to] Can't Post

I also want to clean the paste and not the whole document. I am trying your code and am having troubles with pasteword(). Where do you actually put it? When I put it into function HTMLArea(textarea, config), htmlarea blows up in generate() - HTMLArea.getElementById("textarea", textarea) returns null.

Bill


mikeyb101
Novice

Mar 15, 2004, 8:12 AM

Post #22 of 24 (9663 views)
Shortcut
Re: [bsutton] v3 Word Cleaner & questions [In reply to] Can't Post

Just a quickie for those with the Context Menu plug-in enabled;

change the following line in contxt-menu.js to the italic version:


Code
  

function() { editor.execCommand("paste"); },


function() { editor.execCommand("paste"); editor._wordClean(); },





lunajewel
New User

Mar 25, 2004, 6:36 PM

Post #23 of 24 (9386 views)
Shortcut
Re: [weeezl] v3 Word Cleaner & questions [In reply to] Can't Post


Hi

This is fantastic in theory and i am feeling a bit dim so wondering if some one can help out. I have downloaded 3.0-RC1 as you would know the word cleaner has been incorporated in this release. But i can't get it to work - what am i missing???

In the config I have set this.killWordOnPaste = true;

Do i need to do something else? Please help!


lunajewel
New User

Mar 25, 2004, 7:20 PM

Post #24 of 24 (9384 views)
Shortcut
Re: [lunajewel] v3 Word Cleaner & questions [In reply to] Can't Post

Found out what was wrong so thought i should share.

http://sourceforge.net/tracker/index.php?func=detail&aid=900950&group_id=69750&atid=525656

Very simple a couple of lines need to be rearranged.

 
 
 


Search for (options)