Strip abstract
field to save note space, set new itemData on export
This commit is contained in:
parent
3536a384a9
commit
f6fa81fdac
2 changed files with 56 additions and 32 deletions
|
@ -143,6 +143,25 @@ Zotero.Notes = new function() {
|
||||||
}
|
}
|
||||||
node.removeAttribute('data-attachment-key');
|
node.removeAttribute('data-attachment-key');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nodes = doc.querySelectorAll('.citation[data-citation]');
|
||||||
|
for (var node of nodes) {
|
||||||
|
var citation = node.getAttribute('data-citation');
|
||||||
|
try {
|
||||||
|
citation = JSON.parse(decodeURIComponent(citation));
|
||||||
|
for (var citationItem of citation.citationItems) {
|
||||||
|
var item = await Zotero.EditorInstance.getItemFromURIs(citationItem.uris);
|
||||||
|
if (item) {
|
||||||
|
citationItem.itemData = Zotero.Cite.System.prototype.retrieveItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
citation = encodeURIComponent(JSON.stringify(citation));
|
||||||
|
node.setAttribute('data-citation', citation);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
Zotero.logError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return doc.body.innerHTML;
|
return doc.body.innerHTML;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -223,10 +223,12 @@ class EditorInstance {
|
||||||
// Citation
|
// Citation
|
||||||
let parentItem = attachmentItem.parentID && await Zotero.Items.getAsync(attachmentItem.parentID);
|
let parentItem = attachmentItem.parentID && await Zotero.Items.getAsync(attachmentItem.parentID);
|
||||||
if (parentItem) {
|
if (parentItem) {
|
||||||
|
// TODO: Find a more elegant way to call this
|
||||||
|
let itemData = Zotero.Cite.System.prototype.retrieveItem(parentItem);
|
||||||
|
delete itemData.abstract;
|
||||||
let citationItem = {
|
let citationItem = {
|
||||||
uris: [Zotero.URI.getItemURI(parentItem)],
|
uris: [Zotero.URI.getItemURI(parentItem)],
|
||||||
// TODO: Find a more elegant way to call this method
|
itemData,
|
||||||
itemData: Zotero.Cite.System.prototype.retrieveItem(parentItem),
|
|
||||||
locator: annotation.pageLabel
|
locator: annotation.pageLabel
|
||||||
};
|
};
|
||||||
annotation.citationItem = citationItem;
|
annotation.citationItem = citationItem;
|
||||||
|
@ -283,10 +285,12 @@ class EditorInstance {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (item.isRegularItem()) {
|
if (item.isRegularItem()) {
|
||||||
|
let itemData = Zotero.Cite.System.prototype.retrieveItem(item);
|
||||||
|
delete itemData.abstract;
|
||||||
let citation = {
|
let citation = {
|
||||||
citationItems: [{
|
citationItems: [{
|
||||||
uris: [Zotero.URI.getItemURI(item)],
|
uris: [Zotero.URI.getItemURI(item)],
|
||||||
itemData: Zotero.Cite.System.prototype.retrieveItem(item)
|
itemData
|
||||||
}],
|
}],
|
||||||
properties: {}
|
properties: {}
|
||||||
};
|
};
|
||||||
|
@ -362,7 +366,7 @@ class EditorInstance {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let citationItem = citation.citationItems[0];
|
let citationItem = citation.citationItems[0];
|
||||||
let item = await this._getItemFromURIs(citationItem.uris);
|
let item = await Zotero.EditorInstance.getItemFromURIs(citationItem.uris);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +383,7 @@ class EditorInstance {
|
||||||
let { citation } = message;
|
let { citation } = message;
|
||||||
let items = [];
|
let items = [];
|
||||||
for (let citationItem of citation.citationItems) {
|
for (let citationItem of citation.citationItems) {
|
||||||
let item = await this._getItemFromURIs(citationItem.uris);
|
let item = await Zotero.EditorInstance.getItemFromURIs(citationItem.uris);
|
||||||
if (item) {
|
if (item) {
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
|
@ -453,7 +457,7 @@ class EditorInstance {
|
||||||
citation = JSON.parse(JSON.stringify(citation));
|
citation = JSON.parse(JSON.stringify(citation));
|
||||||
let availableCitationItems = [];
|
let availableCitationItems = [];
|
||||||
for (let citationItem of citation.citationItems) {
|
for (let citationItem of citation.citationItems) {
|
||||||
let item = await this._getItemFromURIs(citationItem.uris);
|
let item = await Zotero.EditorInstance.getItemFromURIs(citationItem.uris);
|
||||||
if (item) {
|
if (item) {
|
||||||
availableCitationItems.push({ ...citationItem, id: item.id });
|
availableCitationItems.push({ ...citationItem, id: item.id });
|
||||||
}
|
}
|
||||||
|
@ -691,31 +695,6 @@ class EditorInstance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _getItemFromURIs(uris) {
|
|
||||||
for (let uri of uris) {
|
|
||||||
// Try getting URI directly
|
|
||||||
try {
|
|
||||||
let item = await Zotero.URI.getURIItem(uri);
|
|
||||||
if (item) {
|
|
||||||
// Ignore items in the trash
|
|
||||||
if (!item.deleted) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try merged item mapping
|
|
||||||
var replacer = await Zotero.Relations.getByPredicateAndObject(
|
|
||||||
'item', Zotero.Relations.replacedItemPredicate, uri
|
|
||||||
);
|
|
||||||
if (replacer.length && !replacer[0].deleted) {
|
|
||||||
return replacer[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the string to go inside a bubble
|
* Builds the string to go inside a bubble
|
||||||
*/
|
*/
|
||||||
|
@ -758,7 +737,7 @@ class EditorInstance {
|
||||||
if (!Array.isArray(citationItem.uris)) {
|
if (!Array.isArray(citationItem.uris)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let item = await this._getItemFromURIs(citationItem.uris);
|
let item = await Zotero.EditorInstance.getItemFromURIs(citationItem.uris);
|
||||||
if (!item && citationItem.itemData) {
|
if (!item && citationItem.itemData) {
|
||||||
item = new Zotero.Item();
|
item = new Zotero.Item();
|
||||||
Zotero.Utilities.itemFromCSLJSON(item, citationItem.itemData);
|
Zotero.Utilities.itemFromCSLJSON(item, citationItem.itemData);
|
||||||
|
@ -974,6 +953,32 @@ class EditorInstance {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This should be moved to utilities
|
||||||
|
static async getItemFromURIs(uris) {
|
||||||
|
for (let uri of uris) {
|
||||||
|
// Try getting URI directly
|
||||||
|
try {
|
||||||
|
let item = await Zotero.URI.getURIItem(uri);
|
||||||
|
if (item) {
|
||||||
|
// Ignore items in the trash
|
||||||
|
if (!item.deleted) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try merged item mapping
|
||||||
|
var replacer = await Zotero.Relations.getByPredicateAndObject(
|
||||||
|
'item', Zotero.Relations.replacedItemPredicate, uri
|
||||||
|
);
|
||||||
|
if (replacer.length && !replacer[0].deleted) {
|
||||||
|
return replacer[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create note from annotations
|
* Create note from annotations
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue