[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kupu-checkins
Subject:    [kupu-checkins] r5235 - in kupu/trunk/kupu: common default
From:       paul () codespeak ! net
Date:       2004-06-22 11:55:32
Message-ID: 20040622115532.EC4CB5A9B0 () thoth ! codespeak ! net
[Download RAW message or body]

Author: paul
Date: Tue Jun 22 13:55:32 2004
New Revision: 5235

Modified:
   kupu/trunk/kupu/common/kupusourceedit.js
   kupu/trunk/kupu/default/sourceedit.kupu
Log:
The start of some improvements on  better/faster cleanup of pasted Word HTML, \
including a temporary toolbar button for cleanup

Modified: kupu/trunk/kupu/common/kupusourceedit.js
==============================================================================
--- kupu/trunk/kupu/common/kupusourceedit.js	(original)
+++ kupu/trunk/kupu/common/kupusourceedit.js	Tue Jun 22 13:55:32 2004
@@ -35,3 +35,37 @@
         kupu._initialized = true;
     };
 };
+
+
+function cleanupSource() {
+    /* Called from toolbar button, convert vomit to filtered XHTML */
+
+    var editorframe = document.getElementById('kupu-editor');
+    var sourcearea = document.getElementById('kupu-editor-textarea');
+    var kupudocroot = kupu.getInnerDocument().documentElement;
+
+    /* Build up the blacklist of things to remove */
+    var blacklist = "";
+    blacklist += "//*[substring-before(name(),':')]"; // Foreign namespaces
+    blacklist += "|//comment()"; // Comment nodes
+    blacklist += "|//@class[.='MsoNormal']"; // Bogus formatting classes
+
+    /* Convert ugly HTML to XHTML and remove some offending elements */
+    var xhtmldoc = Sarissa.getDomDocument();  // XXX Refactor filterContent
+    var transform = kupu._filterContent(kupudocroot).selectSingleNode("body");
+    xhtmldoc.loadXML(transform.xml); // XXX Double-parsing is dumb!!
+    var rejected = xhtmldoc.selectNodes(blacklist);
+    alert("rejected: " + rejected.length);
+    for (i=0; i < rejected.length; i++) {
+        rejected[i].parentNode.removeChild(rejected[i]);
+    }
+
+
+    /* Grab body contents and shove into editor */
+    var contents = xhtmldoc.xml.replace(/<\/?body[^>]*>/g, "");
+    kupudocroot.getElementsByTagName('body')[0].innerHTML = contents;
+
+    alert(kupudocroot.getElementsByTagName('body')[0].innerHTML);
+    return;
+
+}

Modified: kupu/trunk/kupu/default/sourceedit.kupu
==============================================================================
--- kupu/trunk/kupu/default/sourceedit.kupu	(original)
+++ kupu/trunk/kupu/default/sourceedit.kupu	Tue Jun 22 13:55:32 2004
@@ -24,6 +24,12 @@
               title="Edit source"
               i18n:attributes="title"
               onclick="switchSourceEdit()">&#160;</button>
+      <button type="button"
+              class="kupu-cleanup"
+              id="kupu-cleanup-button"
+              title="Cleanup source"
+              i18n:attributes="title"
+              onclick="cleanupSource()"></button>
     </span>
   </kupu:part>
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic