From 4ad2de797f42983ed9a26cf09358fe66bb495601 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 25 Dec 2009 23:39:54 +0000 Subject: [PATCH] Restores proper copying support for notes, with separate output for text, rich text, and HTML-code-as-text (via Copy HTML pref) New hidden prefs: - export.quickCopy.compatibility.indentBlockquotes (default: true) Word and TextEdit don't indent blockquotes on their own and need this, but OO gets it right, so this results in an extra indent - export.quickCopy.compatibility.word (default: false) Adds Word Normal style to paragraphs and adds double-spacing, but OO inserts the conditional style code as a document comment - quickCopy.quoteBlockquotes.plainText (default: true) - quickCopy.quoteBlockquotes.richText (default: true) Adds quotes around blockquote paragraphs, since loss of attribution is serious (and who knows whether all apps that accept rich text even support indenting) Not enabled for HTML code copying, since CSS can be used to render blockquotes as desired Fixes #1397, toggle HTML tags on and off for quick copy of notes --- chrome/content/zotero/xpcom/quickCopy.js | 194 ++++++++++++++++++++--- 1 file changed, 174 insertions(+), 20 deletions(-) diff --git a/chrome/content/zotero/xpcom/quickCopy.js b/chrome/content/zotero/xpcom/quickCopy.js index 22daf86f20..767ebce3f0 100644 --- a/chrome/content/zotero/xpcom/quickCopy.js +++ b/chrome/content/zotero/xpcom/quickCopy.js @@ -165,31 +165,185 @@ Zotero.QuickCopy = new function() { // If all notes, export full content if (allNotes) { var content = []; - for (var i=0; i; - for (var i=0; i{content[i]}

; - p.@style = 'white-space: pre-wrap'; - html.p += p; + XML.prettyPrinting = false; + XML.ignoreWhitespace = false; + var htmlXML =
; + for (var i=0; i' + noteContent + '
'); + } + 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; } - html = html.toXMLString(); + // Raw HTML output + var html = htmlXML.toXMLString(); + + var textXML = htmlXML.copy(); + + // + // Text-only adjustments + // + + 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=Fx3.5 + else { + text = Zotero.Utilities.prototype.trim() + } + + // + // Adjustments for the HTML copied to the clipboard + // + + // Everything seems to like margin-left better than padding-left + var p = htmlXML..p; + for (var i in p) { + var children = p[i].children(); + if (p[i].@style.toString().indexOf("padding-left") != -1) { + p[i].@style = p[i].@style.toString().replace("padding-left", "margin-left"); + } + } + + // 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%; }" + + "li { margin-top:.1pt;margin-right:0in;margin-bottom:.1pt;margin-left:0in; line-height: 200%; }" + + "blockquote p { margin-left: 11px; margin-right: 11px }" + + "" + + "\n" + + htmlXML.toXMLString(); + } + else { + var copyHTML = htmlXML.toXMLString(); + } - // Don't copy HTML, since we don't have rich-text notes and - // copying HTML on Windows just loses newlines (due to - // unsupported white-space: pre-wrap in Word and OO). - /* var content = { - text: contentType == "html" ? html : content.join('\n\n\n'), - html: html - }; - */ - var content = { - text: contentType == "html" ? html : content.join('\n\n\n') + text: contentType == "html" ? html : text, + html: copyHTML }; return content;