diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 33caa05c4..ff6f864ed 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -2624,6 +2624,12 @@ Zotero.Translate.Search.prototype.setIdentifier = function (identifier) { contextObject: "rft_id=info:pmid/" + identifier.PMID }; } + else if (identifier.arXiv) { + search = { + itemType: "journalArticle", + arXiv: identifier.arXiv + }; + } else { throw new Error("Unrecognized identifier"); } diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index d2c924cf7..305344870 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -896,6 +896,22 @@ Zotero.Utilities.Internal = { } } + // Next try arXiv + if (!identifiers.length) { + // arXiv identifiers are extracted without version number + // i.e. 0706.0044v1 is extracted as 0706.0044, + // because arXiv OAI API doesn't allow to access individual versions + let arXiv_RE = /((?:[^A-Za-z]|^)([\-A-Za-z\.]+\/\d{7})(?:(v[0-9]+)|)(?!\d))|((?:\D|^)(\d{4}.\d{4,5})(?:(v[0-9]+)|)(?!\d))/g; + let m; + while ((m = arXiv_RE.exec(text))) { + let arXiv = m[2] || m[5]; + if (arXiv && !foundIDs.has(arXiv)) { + identifiers.push({arXiv: arXiv}); + foundIDs.add(arXiv); + } + } + } + // Finally try for PMID if (!identifiers.length) { // PMID; right now, the longest PMIDs are 8 digits, so it doesn't seem like we'll diff --git a/test/tests/utilities_internalTest.js b/test/tests/utilities_internalTest.js index 621991420..f8c935a82 100644 --- a/test/tests/utilities_internalTest.js +++ b/test/tests/utilities_internalTest.js @@ -153,5 +153,18 @@ describe("Zotero.Utilities.Internal", function () { assert.lengthOf(Object.keys(identifiers[0]), 1); assert.propertyVal(identifiers[0], "PMID", id); }); + + it("should extract multiple old and new style arXivs", async function () { + var identifiers = ZUI.extractIdentifiers("0706.0044 arXiv:0706.00441v1,hep-ex/9809001v1, math.GT/0309135."); + assert.lengthOf(identifiers, 4); + assert.lengthOf(Object.keys(identifiers[0]), 1); + assert.lengthOf(Object.keys(identifiers[1]), 1); + assert.lengthOf(Object.keys(identifiers[2]), 1); + assert.lengthOf(Object.keys(identifiers[3]), 1); + assert.propertyVal(identifiers[0], "arXiv", "0706.0044"); + assert.propertyVal(identifiers[1], "arXiv", "0706.00441"); + assert.propertyVal(identifiers[2], "arXiv", "hep-ex/9809001"); + assert.propertyVal(identifiers[3], "arXiv", "math.GT/0309135"); + }); }); })