From 136e7879c8e065738b62114436a6cc17f142fc0c Mon Sep 17 00:00:00 2001
From: Simon Kornblith
Date: Sat, 14 Jul 2012 18:56:36 -0400
Subject: [PATCH] Kill E4X in QuickCopy
---
chrome/content/zotero/xpcom/quickCopy.js | 218 ++++++++---------------
1 file changed, 78 insertions(+), 140 deletions(-)
diff --git a/chrome/content/zotero/xpcom/quickCopy.js b/chrome/content/zotero/xpcom/quickCopy.js
index c6a7117ded..5e20deab6e 100644
--- a/chrome/content/zotero/xpcom/quickCopy.js
+++ b/chrome/content/zotero/xpcom/quickCopy.js
@@ -191,99 +191,67 @@ Zotero.QuickCopy = new function() {
// If all notes, export full content
if (allNotes) {
- var content = [];
- default xml namespace = '';
- XML.prettyPrinting = false;
- XML.ignoreWhitespace = false;
- var htmlXML = ;
+ var content = [],
+ parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
+ .createInstance(Components.interfaces.nsIDOMParser),
+ doc = parser.parseFromString('', 'text/html'),
+ textDoc = parser.parseFromString('', 'text/html'),
+ container = doc.documentElement,
+ textContainer = textDoc.documentElement;
for (var i=0; i'
- + noteContent
- // is the only HTML entity we allow in
- // notes, and it's not valid XML
- .replace(/ /g, ' ')
- + '');
- }
- catch (e) {
- Zotero.debug(e);
- Zotero.debug("Couldn't parse note as HTML -- try as CDATA", 2);
- try {
- var noteDiv = new XML('');
- }
- catch (e) {
- Zotero.debug("Skipping note", 2);
- continue;
- }
- }
-
- htmlXML.div += noteDiv;
+ var div = doc.createElement("div");
+ div.className = "zotero-note";
+ div.insertAdjacentHTML('afterbegin', notes[i].getNote());
+ container.appendChild(div);
+ textContainer.appendChild(textDoc.importNode(div, true));
}
// Raw HTML output
- var html = htmlXML.toXMLString();
+ var html = container.outerHTML;
- var textXML = htmlXML.copy();
+ // Add placeholders for newlines between notes
+ if (notes.length > 1) {
+ var divs = Zotero.Utilities.xpath(container, "div"),
+ textDivs = Zotero.Utilities.xpath(textContainer, "div");
+ for (var i=1, len=divs.length; i 1) {
- var divs = textXML.div;
- for (var i=0, len=divs.length(); i--------------------------------------------------
;
- }
- }
-
- if (Zotero.Prefs.get('export.quickCopy.quoteBlockquotes.plainText')) {
- // Add quotes around blockquote paragraphs
- var nodes = textXML..blockquote;
- for (var i in nodes) {
- for (var j=0, len=nodes[i].p.length(); j 1) {
- var divs = htmlXML.div;
- for (var i=0, len=divs.length(); i----------------------------------------------------------------------;
- }
- }
-
- // Add quotes around blockquote paragraphs
- if (Zotero.Prefs.get('export.quickCopy.quoteBlockquotes.richText')) {
- var nodes = htmlXML..blockquote;
- for (var i in nodes) {
- for (var j=0, len=nodes[i].p.length(); j"
+ "p { margin-top:.1pt;margin-right:0in;margin-bottom:.1pt;margin-left:0in; line-height: 200%; }"
@@ -376,10 +314,10 @@ Zotero.QuickCopy = new function() {
+ "blockquote p { margin-left: 11px; margin-right: 11px }"
+ ""
+ "\n"
- + htmlXML.toXMLString();
+ + container.outerHTML;
}
else {
- var copyHTML = htmlXML.toXMLString();
+ var copyHTML = container.outerHTML;
}
var content = {