From b899e5694ae981c0b660cccf1a41758589f023a5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 16 Jul 2019 02:03:07 -0400 Subject: [PATCH] Update citeproc-js to 1.2.17 --- chrome/content/zotero/xpcom/citeproc.js | 237 +++++++++++------------- 1 file changed, 105 insertions(+), 132 deletions(-) diff --git a/chrome/content/zotero/xpcom/citeproc.js b/chrome/content/zotero/xpcom/citeproc.js index 508366d50d..cd50955012 100644 --- a/chrome/content/zotero/xpcom/citeproc.js +++ b/chrome/content/zotero/xpcom/citeproc.js @@ -59,7 +59,7 @@ Copyright (c) 2009-2019 Frank Bennett var CSL = { - PROCESSOR_VERSION: "1.2.13", + PROCESSOR_VERSION: "1.2.17", error: function(str) { // default error function if ("undefined" === typeof Error) { @@ -1140,39 +1140,8 @@ var CSL = { UPDATE_GROUP_CONTEXT_CONDITION: function (state, termtxt, valueTerm) { if (state.tmp.group_context.tip.condition) { if (state.tmp.group_context.tip.condition.test) { - var testres; - if (state.tmp.group_context.tip.condition.test === "empty-label") { - testres = !termtxt; - } else if (state.tmp.group_context.tip.condition.test === "empty-label-no-decor") { - testres = !termtxt || termtxt.indexOf("%s") > -1; - } else if (state.tmp.group_context.tip.condition.test === "comma-safe") { - var empty = !termtxt; - var alpha = termtxt.slice(0,1).match(CSL.ALL_ROMANESQUE_REGEXP); - var num = state.tmp.just_did_number; - if (empty) { - testres = true; - } else if (num) { - if (alpha && !valueTerm) { - testres = true; - } else { - testres = false; - } - } else { - if (alpha && !valueTerm) { - testres = true; - } else { - testres = false; - } - } - } - if (testres) { - state.tmp.group_context.tip.force_suppress = false; - } else { - state.tmp.group_context.tip.force_suppress = true; - } - if (state.tmp.group_context.tip.condition.not) { - state.tmp.group_context.tip.force_suppress = !state.tmp.group_context.tip.force_suppress; - } + state.tmp.group_context.tip.condition.termtxt = termtxt; + state.tmp.group_context.tip.condition.valueTerm = valueTerm; } } else { // If not inside a conditional group, raise numeric flag @@ -1185,6 +1154,50 @@ var CSL = { } }, + EVALUATE_GROUP_CONDITION: function(state, flags) { + var testres; + if (flags.condition.test === "empty-label") { + testres = !flags.condition.termtxt; + } else if (flags.condition.test === "empty-label-no-decor") { + testres = !flags.condition.termtxt || flags.condition.termtxt.indexOf("%s") > -1; + } else if (flags.condition.test === "comma-safe") { + var empty = !flags.condition.termtxt; + var termStartAlpha = false; + if (flags.condition.termtxt) { + termStartAlpha = flags.condition.termtxt.slice(0,1).match(CSL.ALL_ROMANESQUE_REGEXP); + } + var num = state.tmp.just_did_number; + if (empty) { + // i.e. Big L. Rev. 100, 102 + // Little L. Rev. 102 + // L. Rev. for Plan 9, 102 + if (num) { + testres = true; + } else { + testres = false; + } + } else if (flags.condition.valueTerm) { + // i.e. Ibid. at 102 + testres = false; + } else { + if (termStartAlpha) { + testres = true; + } else { + testres = false; + } + } + } + if (testres) { + var force_suppress = false; + } else { + var force_suppress = true; + } + if (flags.condition.not) { + force_suppress = !force_suppress; + } + return force_suppress; + }, + SYS_OPTIONS: [ "prioritize_disambiguate_condition", "csl_reverse_lookup_support", @@ -6963,12 +6976,14 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, for (k = 0, klen = citations[j].sortedItems.length; k < klen; k += 1) { item = citations[j].sortedItems[k]; var myid = item[0].id; + var myxloc = item[1]["locator-extra"]; var mylocator = item[1].locator; var mylabel = item[1].label; if (item[0].legislation_id) { myid = item[0].legislation_id; } var incitationid; + var incitationxloc; if (k > 0) { // incitationid is only reached in the else branch // following "undefined" === typeof first_ref[myid] @@ -6977,10 +6992,12 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, incitationid = onecitation.sortedItems[k - 1][0].legislation_id; } else { incitationid = onecitation.sortedItems[k - 1][1].id; + incitationxloc = onecitation.sortedItems[k - 1][1]["locator-extra"]; //if (onecitation.sortedItems[k-1][1].parallel === "last") { for (var l=k-2; l>-1; l--) { if (onecitation.sortedItems[l][1].parallel === "first") { incitationid = onecitation.sortedItems[l][1].id; + incitationxloc = onecitation.sortedItems[l][1]["locator-extra"]; } } //} @@ -7027,6 +7044,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, } } var oldlastid; + var oldlastxloc; if ("undefined" === typeof first_ref[myid] && onecitation.properties.mode !== "author-only") { first_ref[myid] = onecitation.properties.noteIndex; @@ -7043,18 +7061,24 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, // var ibidme = false; var suprame = false; + var prevCitation = null; + if (j > 0) { + var prevCitation = citations[j-1]; + } + var thisCitation = citations[j]; // XXX Ugly, but This is used in the second else-if branch condition below. if (j > 0) { var old_last_id_offset = 1; - if (citations[j-1].properties.mode === "author-only" && j > 1) { + if (prevCitation.properties.mode === "author-only" && j > 1) { old_last_id_offset = 2; } oldlastid = citations[j - old_last_id_offset].sortedItems.slice(-1)[0][1].id; - if (citations[j - 1].sortedItems[0].slice(-1)[0].legislation_id) { - oldlastid = citations[j - 1].sortedItems[0].slice(-1)[0].legislation_id; + oldlastxloc = citations[j - old_last_id_offset].sortedItems.slice(-1)[0][1]["locator-extra"]; + if (prevCitation.sortedItems[0].slice(-1)[0].legislation_id) { + oldlastid = prevCitation.sortedItems[0].slice(-1)[0].legislation_id; } } - if (j > 0 && parseInt(k, 10) === 0 && citations[j - 1].properties.noteIndex !== citations[j].properties.noteIndex) { + if (j > 0 && k === 0 && prevCitation.properties.noteIndex !== thisCitation.properties.noteIndex) { // Case 1: source in previous onecitation // (1) Threshold conditions // (a) there must be a previous onecitation with one item @@ -7065,12 +7089,14 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, // (this has some jiggery-pokery in it for parallels) var useme = false; // XXX Can oldid be equated with oldlastid, I wonder ... - var oldid = citations[j - 1].sortedItems[0][0].id; - if (citations[j - 1].sortedItems[0][0].legislation_id) { - oldid = citations[j - 1].sortedItems[0][0].legislation_id; + var oldid = prevCitation.sortedItems[0][0].id; + if (prevCitation.sortedItems[0][0].legislation_id) { + oldid = prevCitation.sortedItems[0][0].legislation_id; } - if ((oldid == myid && citations[j - 1].properties.noteIndex >= (citations[j].properties.noteIndex - 1))) { - if (citationsInNote[citations[j - 1].properties.noteIndex] === 1 || citations[j - 1].properties.noteIndex === 0) { + if ((oldid == myid && prevCitation.properties.noteIndex >= (thisCitation.properties.noteIndex - 1))) { + var prevxloc = prevCitation.sortedItems[0][1]["locator-extra"]; + var thisxloc = thisCitation.sortedItems[0][1]["locator-extra"]; + if ((citationsInNote[prevCitation.properties.noteIndex] === 1 || prevCitation.properties.noteIndex === 0) && prevxloc === thisxloc) { useme = true; } } @@ -7079,15 +7105,15 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, } else { suprame = true; } - } else if (k > 0 && incitationid == myid) { + } else if (k > 0 && incitationid == myid && incitationxloc == myxloc) { // Case 2: immediately preceding source in this onecitation // (1) Threshold conditions // (a) there must be an imediately preceding reference to the // same item in this onecitation; and ibidme = true; - } else if (k === 0 && j > 0 && citations[j - 1].properties.noteIndex == citations[j].properties.noteIndex - && citations[j - 1].sortedItems.length - && oldlastid == myid) { + } else if (k === 0 && j > 0 && prevCitation.properties.noteIndex == thisCitation.properties.noteIndex + && prevCitation.sortedItems.length + && oldlastid == myid && oldlastxloc == myxloc) { // ... in case there are separate citations in the same note ... // Case 2 [take 2]: immediately preceding source in this onecitation // (1) Threshold conditions @@ -7496,7 +7522,6 @@ CSL.getAmbiguousCite = function (Item, disambig, visualForm, item) { this.tmp.suppress_decorations = true; this.tmp.just_looking = true; - // Do not reset shadow_numbers when running ambiguous cites CSL.getCite.call(this, Item, itemSupp, null, false); // !!! for (var i=0,ilen=this.output.queue.length;i= trysubjurisdictions) { - return true; - } - return false; - }; - this.tests.push(func); -}; - CSL.Attributes["@is-plural"] = function (state, arg) { this.tests ? {} : this.tests = []; var func = function (Item) { @@ -15844,26 +15846,6 @@ CSL.Attributes["@locale"] = function (state, arg) { } }; -CSL.Attributes["@authority-residue"] = function (state, arg) { - this.tests ? {} : this.tests = []; - var maketest = function () { - var succeed = (arg === "true") ? true : false; - return function(Item) { - if (!Item.authority || !Item.authority[0] || !Item.authority[0].family) { - return !succeed; - } - var varLen = Item.authority[0].family.split("|").length; - var stopLast = state.tmp.authority_stop_last; - if ((varLen + stopLast) > 0) { - return succeed; - } else { - return !succeed; - } - }; - }; - this.tests.push(maketest()); -}; - CSL.Attributes["@alternative-node-internal"] = function (state) { this.tests ? {} : this.tests = []; var maketest = function () { @@ -15968,10 +15950,6 @@ CSL.Attributes["@no-repeat"] = function (state, arg) { }; -CSL.Attributes["@jurisdiction-depth"] = function (state, arg) { - this.strings.jurisdiction_depth = parseInt(arg, 10); -}; - CSL.Attributes["@require"] = function (state, arg) { this.strings.require = arg; @@ -16241,9 +16219,6 @@ CSL.Attributes["@publisher-and"] = function (state, arg) { this.strings["publisher-and"] = arg; }; -CSL.Attributes["@newdate"] = function () {}; - - CSL.Attributes["@givenname-disambiguation-rule"] = function (state, arg) { if (CSL.GIVENNAME_DISAMBIGUATION_RULES.indexOf(arg) > -1) { state.citation.opt["givenname-disambiguation-rule"] = arg; @@ -16690,7 +16665,7 @@ CSL.Parallel.prototype.getRepeats = function(prev, curr) { if (key.match(rex)) { continue; } - if (typeof prev[key] === "string") { + if (typeof prev[key] === "string" || !prev[key]) { if (prev[key] && prev[key] === curr[key]) { ret[key] = true; } @@ -16750,6 +16725,7 @@ CSL.Parallel.prototype.StartCitation = function (sortedItems, out) { sortedItems[i-1][1].parallel = "first"; sortedItems[i][1].parallel = "mid"; sortedItems[i][1].repeats = this.getRepeats(prev, curr); + sortedItems[i-1][1].repeats = sortedItems[i][1].repeats; if (!sortedItems[i][1].prefix) { sortedItems[i][1].prefix = ", "; } @@ -16766,15 +16742,20 @@ CSL.Parallel.prototype.StartCitation = function (sortedItems, out) { } delete seriesRels[curr.id]; sortedItems[i][1].repeats = this.getRepeats(prev, curr); + //sortedItems[i-1][1].repeats = sortedItems[i][1].repeats; this.state.registry.registry[masterID].siblings.push(curr.id); } else { sortedItems[i-1][1].parallel = "last"; + sortedItems[i][1].repeats = this.getRepeats(prev, curr); seriesRels = false; } } if (i === (sortedItems.length-1)) { if (sortedItems[i][1].parallel === "mid") { sortedItems[i][1].parallel = "last"; + sortedItems[i][1].repeats = this.getRepeats(prev, curr); + } else if (sortedItems[i][1].parallel !== "last") { + delete sortedItems[i][1].repeats; } } } @@ -16786,22 +16767,17 @@ CSL.Parallel.prototype.purgeGroupsIfParallel = function () { for (var i = this.parallel_conditional_blobs_list.length - 1; i > -1; i += -1) { var obj = this.parallel_conditional_blobs_list[i]; if (!obj.result && !obj.repeats) { - //this.state.sys.print(i + " No action [render] " + obj.id); purgeme = false; } else { if (obj.condition) { var purgeme = true; if (obj.result === obj.condition) { - //this.state.sys.print(i + " Position match [render] "+obj.id); purgeme = false; } - //else { - // this.state.sys.print(i + " Position non-match [not-render] "+obj.id + " " + obj.condition + " " + obj.result); - //} - } else if (obj.repeats) { + } + if (purgeme && obj.norepeat && obj.repeats) { purgeme = false; var matches = 0; - //this.state.sys.print(obj.norepeat) for (var j=0,jlen=obj.norepeat.length; j obj.pos) { @@ -19971,9 +19942,11 @@ CSL.Util.PageRangeMangler.getFunction = function (state, rangeType) { minimize = function (lst, minchars, isyear) { len = lst.length; for (var i = 1, ilen = lst.length; i < ilen; i += 2) { - lst[i][3] = minimize_internal(lst[i][1], lst[i][3], minchars, isyear); - if (lst[i][2].slice(1) === lst[i][0]) { - lst[i][2] = range_delimiter; + if ("object" === typeof lst[i]) { + lst[i][3] = minimize_internal(lst[i][1], lst[i][3], minchars, isyear); + if (lst[i][2].slice(1) === lst[i][0]) { + lst[i][2] = range_delimiter; + } } } return stringify(lst);