From 72960a6a6dbb2213d9f8a92bc5b9d8ad5e5fd338 Mon Sep 17 00:00:00 2001 From: julmis Date: Tue, 19 Apr 2005 12:47:29 +0000 Subject: [PATCH] CleanWord fix - Don't strip carriage returns --- lib/editor/htmlarea.php | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/editor/htmlarea.php b/lib/editor/htmlarea.php index e713b75c560..575bdcbc4c0 100644 --- a/lib/editor/htmlarea.php +++ b/lib/editor/htmlarea.php @@ -933,9 +933,9 @@ HTMLArea.prototype._wordClean = function() { if (D.indexOf("class=Mso") >= 0 || D.indexOf("mso") >= 0 || D.indexOf("Mso") >= 0) { // make one line - D = D.replace(/\r\n/g, ' '). - replace(/\n/g, ' '). - replace(/\r/g, ' '). + D = D.replace(/\r\n/g, '\[br\]'). + replace(/\n/g, ''). + replace(/\r/g, ''). replace(/\ \;/g,' '); // keep tags, strip attributes @@ -976,6 +976,7 @@ HTMLArea.prototype._wordClean = function() { //D = D.replace(/<\/strong>/gi,''). //replace(/<\/i>/gi,''). //replace(/]*><\/P>/gi,''); + D = D.replace(/\s?<\/h[1-6]+>/gi, ''); // Remove empty headings // nuke double tags oldlen = D.length + 1; @@ -991,6 +992,28 @@ HTMLArea.prototype._wordClean = function() { // nuke double spaces D = D.replace(/ */gi,' '); + // Split into lines and remove + // empty lines and add carriage returns back + var splitter = /\[br\]/g; + var emptyLine = /^\s+\s+$/g; + var strHTML = ''; + var toLines = D.split(splitter); + for (var i = 0; i < toLines.length; i++) { + var line = toLines[i]; + if (line.length < 1) { + continue; + } + + if (emptyLine.test(line)) { + continue; + } + + line = line.replace(/^\s+\s+$/g, ''); + strHTML += line + '\n'; + } + D = strHTML; + strHTML = ''; + this.setHTML(D); this.updateToolbar(); } @@ -1848,9 +1871,11 @@ HTMLArea.prototype.execCommand = function(cmdID, UI, param) { case "copy": case "paste": try { - if (this.config.killWordOnPaste) - this._wordClean(); + // Paste first then clean this._doc.execCommand(cmdID, UI, param); + if (this.config.killWordOnPaste) { + this._wordClean(); + } } catch (e) { if (HTMLArea.is_gecko) { if (confirm("Unprivileged scripts cannot access Cut/Copy/Paste programatically " + @@ -2288,8 +2313,10 @@ HTMLArea.getHTML = function(root, outputRoot, editor) { html = ""; break; // skip comments, for now. } - //html = html.replace(/^\n+/, ''); - return HTMLArea.formathtml(html); + + //return HTMLArea.formathtml(html); + // formathtml doesn't work properly yet!!! + return html; }; HTMLArea.prototype.stripBaseURL = function(string) {