Fix invalid HTML in note from Quick Copy

A <body> was included with the note element outside of it.
This commit is contained in:
Dan Stillman 2020-09-09 23:10:25 -04:00
parent 4838726b87
commit 4ac35ecda3
2 changed files with 20 additions and 7 deletions

View file

@ -278,13 +278,15 @@ Zotero.QuickCopy = new function() {
// If all notes, export full content // If all notes, export full content
if (allNotes) { if (allNotes) {
var content = [], var content = [];
parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] let parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
.createInstance(Components.interfaces.nsIDOMParser), .createInstance(Components.interfaces.nsIDOMParser);
doc = parser.parseFromString('<div class="zotero-notes"/>', 'text/html'), let docHTML = '<html><body><div class="zotero-notes"/></body></html>';
textDoc = parser.parseFromString('<div class="zotero-notes"/>', 'text/html'), let doc = parser.parseFromString(docHTML, 'text/html');
container = doc.documentElement, let textDoc = parser.parseFromString(docHTML, 'text/html');
textContainer = textDoc.documentElement; let container = doc.body.firstChild;
let textContainer = textDoc.body.firstChild;
for (var i=0; i<notes.length; i++) { for (var i=0; i<notes.length; i++) {
var div = doc.createElement("div"); var div = doc.createElement("div");
div.className = "zotero-note"; div.className = "zotero-note";

View file

@ -73,6 +73,17 @@ describe("Zotero.QuickCopy", function() {
assert.isTrue(worked); assert.isTrue(worked);
assert.isTrue(content.trim().startsWith('@')); assert.isTrue(content.trim().startsWith('@'));
}); });
it("should copy note content", async function () {
var item = await createDataObject('item', { itemType: 'note', note: '<p>Foo</p>' });
var format = 'bibliography=http://www.zotero.org/styles/apa';
Zotero.Prefs.set(prefName, format);
var content = Zotero.QuickCopy.getContentFromItems([item], format);
assert.propertyVal(content, 'text', 'Foo');
assert.propertyVal(content, 'html', '<div class=\"zotero-notes\"><div class=\"zotero-note\"><p>Foo</p></div></div>');
});
}); });
it("should generate bibliography in default locale if Quick Copy locale not set", async function () { it("should generate bibliography in default locale if Quick Copy locale not set", async function () {