diff --git a/chrome/content/zotero/xpcom/citeproc.js b/chrome/content/zotero/xpcom/citeproc.js index ea1497980c..44dff5eb26 100644 --- a/chrome/content/zotero/xpcom/citeproc.js +++ b/chrome/content/zotero/xpcom/citeproc.js @@ -1,35 +1,30 @@ /* - * Copyright (c) 2009-2016 Frank Bennett - * - * This program is free software: you can redistribute it and/or - * modify it under EITHER - * - * * the terms of the Common Public Attribution License (CPAL) as - * published by the Open Source Initiative, either version 1 of - * the CPAL, or (at your option) any later version; OR - * - * * the terms of the GNU Affero General Public License (AGPL) - * as published by the Free Software Foundation, either version - * 3 of the AGPL, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Affero General Public License for more details. - * - * You should have received copies of the Common Public Attribution - * License and of the GNU Affero General Public License along with - * this program. If not, see or - * respectively. - */ +Copyright (c) 2009-2019 Frank Bennett + This program is free software: you can redistribute it and/or + modify it under EITHER + + * the terms of the Common Public Attribution License (CPAL) as + published by the Open Source Initiative, either version 1 of + the CPAL, or (at your option) any later version; OR + + * the terms of the GNU Affero General Public License (AGPL) + as published by the Free Software Foundation, either version + 3 of the AGPL, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received copies of the Common Public Attribution + License and of the GNU Affero General Public License along with + this program. If not, see or + respectively. +*/ var CSL = { - PROCESSOR_VERSION: "1.1.215", - CONDITION_LEVEL_TOP: 1, - CONDITION_LEVEL_BOTTOM: 2, - PLAIN_HYPHEN_REGEX: /(?:[^\\]-|\u2013)/, + PROCESSOR_VERSION: "1.1.228", LOCATOR_LABELS_REGEXP: new RegExp("^((art|ch|subch|col|fig|l|n|no|op|p|pp|para|subpara|pt|r|sec|subsec|sv|sch|tit|vrs|vol)\\.)\\s+(.*)"), - STATUTE_SUBDIV_GROUPED_REGEX: /((?:^| )(?:art|bk|ch|subch|col|fig|fol|l|n|no|op|p|pp|para|subpara|pt|r|sec|subsec|sv|sch|tit|vrs|vol)\. *)/g, STATUTE_SUBDIV_PLAIN_REGEX: /(?:(?:^| )(?:art|bk|ch|subch|col|fig|fol|l|n|no|op|p|pp|para|subpara|pt|r|sec|subsec|sv|sch|tit|vrs|vol)\. *)/, STATUTE_SUBDIV_PLAIN_REGEX_FRONT: /(?:^\s*[.,;]*\s*(?:art|bk|ch|subch|col|fig|fol|l|n|no|op|p|pp|para|subpara|pt|r|sec|subsec|sv|sch|tit|vrs|vol)\. *)/, STATUTE_SUBDIV_STRINGS: { @@ -131,37 +126,33 @@ var CSL = { "regulation": true, "standard": true }, - NestedBraces: [ - ["(", "["], - [")", "]"] - ], checkNestedBrace: function(state) { if (state.opt.xclass === "note") { this.depth = 0; this.update = function(str) { - var str = str ? str : ''; + var str = str ? str : ""; var lst = str.split(/([\(\)])/); for (var i=1,ilen=lst.length;i less && str.length < more && parseInt(str)) { - return true - } else { - return false; - } - }, - isDateString: function(str) { - if (!str) return false; - var strLst = str.split("-"); - if (strLst.length > 0) { - if (!this.isDatePart(strLst[0], 3, 5)) { - return false; - } - } - if (strLst.length > 1) { - if (!this.isDatePart(strLst[1], 0, 3)) { - return false - } - } - if (strLst.length > 2) { - if (!this.isDatePart(strLst[2], 0, 3)) { - return false - } - } - if (strLst.length > 3) { - return false; - } - return true; - }, parseNoteFieldHacks: function(Item, validFieldsForType, allowDateOverride) { - if ("string" !== typeof Item.note) return; + if ("string" !== typeof Item.note) { + return; + } var elems = []; var lines = Item.note.split('\n'); - var lastline = ""; for (var i=0, ilen=lines.length; i0 || j>1) && !elems[j-1].match(CSL.NOTE_FIELD_REGEXP)) { - break + break; } else { elems[j] = '\n' + elems[j].slice(2,-1).trim() + '\n'; } @@ -338,7 +303,7 @@ var CSL = { if (key === "type") { Item.type = val; lines[i] = ""; - } else if (CSL.DATE_VARIABLES.indexOf(key) > -1) { + } else if (CSL.DATE_VARIABLES.indexOf(key.replace(/^alt-/, "")) > -1) { if (allowDateOverride) { Item[key] = {raw: val}; if (!validFieldsForType || (validFieldsForType[key] && this.isDateString(val))) { @@ -346,7 +311,7 @@ var CSL = { } } } else if (!Item[key]) { - if (CSL.NAME_VARIABLES.indexOf(key) > -1) { + if (CSL.NAME_VARIABLES.indexOf(key.replace(/^alt-/, "")) > -1) { if (!names[key]) { names[key] = []; } @@ -371,7 +336,7 @@ var CSL = { } if (validFieldsForType) { if (lines[offset].trim()) { - lines[offset] = '\n' + lines[offset] + lines[offset] = '\n' + lines[offset]; } for (var i=offset-1;i>-1;i--) { if (!lines[i].trim()) { @@ -381,6 +346,42 @@ var CSL = { } Item.note = lines.join("\n").trim(); }, + checkPrefixSpaceAppend: function (state, prefix) { + if (!prefix) { + prefix = ""; + } + var sp = ""; + var test_prefix = prefix.replace(/<[^>]+>/g, "").replace(/["'\u201d\u2019\u00bb\u202f\u00a0 ]+$/g,""); + var test_char = test_prefix.slice(-1); + if (test_prefix.match(CSL.ENDSWITH_ROMANESQUE_REGEXP)) { + sp = " "; + } else if (CSL.TERMINAL_PUNCTUATION.slice(0,-1).indexOf(test_char) > -1) { + sp = " "; + } else if (test_char.match(/[\)\],0-9]/)) { + sp = " "; + } + var prefix = (prefix + sp).replace(/\s+/g, " "); + return prefix; + }, + checkIgnorePredecessor: function(state, prefix) { + var ignorePredecessor = false; + var test_prefix = prefix.replace(/<[^>]+>/g, "").replace(/["'\u201d\u2019\u00bb\u202f\u00a0 ]+$/g,""); + var test_char = test_prefix.slice(-1); + if (CSL.TERMINAL_PUNCTUATION.slice(0,-1).indexOf(test_char) > -1 && prefix.trim().indexOf(" ") > -1) { + state.tmp.term_predecessor = false; + return true; + } + return false; + }, + checkSuffixSpacePrepend: function(state, suffix) { + if (!suffix) { + return ""; + } + if (suffix.match(CSL.STARTSWITH_ROMANESQUE_REGEXP) || ['[','('].indexOf(suffix.slice(0,1)) > -1) { + suffix = " " + suffix; + } + return suffix; + }, GENDERS: ["masculine", "feminine"], ERROR_NO_RENDERED_FORM: 1, PREVIEW: "Just for laughs.", @@ -399,30 +400,23 @@ var CSL = { AFTER: 2, DESCENDING: 1, ASCENDING: 2, - ONLY_FIRST: 1, - ALWAYS: 2, - ONLY_LAST: 3, - FINISH: 1, POSITION_FIRST: 0, POSITION_SUBSEQUENT: 1, POSITION_IBID: 2, POSITION_IBID_WITH_LOCATOR: 3, - MARK_TRAILING_NAMES: true, POSITION_TEST_VARS: ["position", "first-reference-note-number", "near-note"], - AREAS: ["citation", "citation_sort", "bibliography", "bibliography_sort"], + AREAS: ["citation", "citation_sort", "bibliography", "bibliography_sort", "intext"], CITE_FIELDS: ["first-reference-note-number", "locator", "locator-extra"], - MINIMAL_NAME_FIELDS: ["literal", "family"], SWAPPING_PUNCTUATION: [".", "!", "?", ":", ","], TERMINAL_PUNCTUATION: [":", ".", ";", "!", "?", " "], NONE: 0, NUMERIC: 1, POSITION: 2, - COLLAPSE_VALUES: ["citation-number", "year", "year-suffix"], + TRIGRAPH: 3, DATE_PARTS: ["year", "month", "day"], DATE_PARTS_ALL: ["year", "month", "day", "season"], DATE_PARTS_INTERNAL: ["year", "month", "day", "year_end", "month_end", "day_end"], NAME_PARTS: ["non-dropping-particle", "family", "given", "dropping-particle", "suffix", "literal"], - DECORABLE_NAME_PARTS: ["given", "family", "suffix"], DISAMBIGUATE_OPTIONS: [ "disambiguate-add-names", "disambiguate-add-givenname", @@ -461,7 +455,7 @@ var CSL = { PREFIX_PUNCTUATION: /[.;:]\s*$/, SUFFIX_PUNCTUATION: /^\s*[.;:,\(\)]/, NUMBER_REGEXP: /(?:^\d+|\d+$)/, - NAME_INITIAL_REGEXP: /^([A-Z\u0e01-\u0e5b\u00c0-\u017f\u0400-\u042f\u0590-\u05d4\u05d6-\u05ff\u0600-\u06ff\u0370\u0372\u0376\u0386\u0388-\u03ab\u03e2\u03e4\u03e6\u03e8\u03ea\u03ec\u03ee\u03f4\u03f7\u03fd-\u03ff])([a-zA-Z\u0e01-\u0e5b\u00c0-\u017f\u0400-\u052f\u0600-\u06ff\u0370-\u03ff\u1f00-\u1fff]*|)/, + NAME_INITIAL_REGEXP: /^([A-Z\u0e01-\u0e5b\u00c0-\u017f\u0400-\u042f\u0590-\u05d4\u05d6-\u05ff\u0600-\u06ff\u0370\u0372\u0376\u0386\u0388-\u03ab\u03e2\u03e4\u03e6\u03e8\u03ea\u03ec\u03ee\u03f4\u03f7\u03fd-\u03ff])([a-zA-Z\u0e01-\u0e5b\u00c0-\u017f\u0400-\u052f\u0600-\u06ff\u0370-\u03ff\u1f00-\u1fff]*|)(\.)*/, ROMANESQUE_REGEXP: /[-0-9a-zA-Z\u0e01-\u0e5b\u00c0-\u017f\u0370-\u03ff\u0400-\u052f\u0590-\u05d4\u05d6-\u05ff\u1f00-\u1fff\u0600-\u06ff\u200c\u200d\u200e\u0218\u0219\u021a\u021b\u202a-\u202e]/, ROMANESQUE_NOT_REGEXP: /[^a-zA-Z\u0e01-\u0e5b\u00c0-\u017f\u0370-\u03ff\u0400-\u052f\u0590-\u05d4\u05d6-\u05ff\u1f00-\u1fff\u0600-\u06ff\u200c\u200d\u200e\u0218\u0219\u021a\u021b\u202a-\u202e]/g, STARTSWITH_ROMANESQUE_REGEXP: /^[&a-zA-Z\u0e01-\u0e5b\u00c0-\u017f\u0370-\u03ff\u0400-\u052f\u0590-\u05d4\u05d6-\u05ff\u1f00-\u1fff\u0600-\u06ff\u200c\u200d\u200e\u0218\u0219\u021a\u021b\u202a-\u202e]/, @@ -512,6 +506,7 @@ var CSL = { "page", "issue", "locator", + "locator-extra", "number", "number-of-pages", "number-of-volumes", @@ -523,12 +518,12 @@ var CSL = { "issued", "event-date", "accessed", - "container", "original-date", "publication-date", - "original-date", "available-date", - "submitted" + "submitted", + "alt-issued", + "alt-event" ], TITLE_FIELD_SPLITS: function(seg) { var keys = ["title", "short", "main", "sub"]; @@ -538,32 +533,6 @@ var CSL = { } return ret; }, - TAG_USEALL: function (str) { - var ret, open, close, end; - ret = [""]; - open = str.indexOf("<"); - close = str.indexOf(">"); - while (open > -1 && close > -1) { - if (open > close) { - end = open + 1; - } else { - end = close + 1; - } - if (open < close && str.slice(open + 1, close).indexOf("<") === -1) { - ret[ret.length - 1] += str.slice(0, open); - ret.push(str.slice(open, close + 1)); - ret.push(""); - str = str.slice(end); - } else { - ret[ret.length - 1] += str.slice(0, close + 1); - str = str.slice(end); - } - open = str.indexOf("<"); - close = str.indexOf(">"); - } - ret[ret.length - 1] += str; - return ret; - }, demoteNoiseWords: function (state, fld, drop_or_demote) { var SKIP_WORDS = state.locale[state.opt.lang].opts["leading-noise-words"]; if (fld && drop_or_demote) { @@ -599,7 +568,7 @@ var CSL = { langs.push(lang); } } - for (var j=0,jlen=langs.length;j -1; ppos += -1) { @@ -2957,10 +2930,9 @@ CSL.Engine.prototype.configureTokenList = function (tokens) { CSL.Node[token.name].configure.call(token, this, ppos); } } -} +}; CSL.Engine.prototype.refetchItems = function (ids) { - var ret, pos, len; - ret = []; + var ret = []; for (var i = 0, ilen = ids.length; i < ilen; i += 1) { ret.push(this.refetchItem("" + ids[i])); } @@ -2968,7 +2940,7 @@ CSL.Engine.prototype.refetchItems = function (ids) { }; CSL.ITERATION = 0; CSL.Engine.prototype.retrieveItem = function (id) { - var Item, m, pos, len, mm, i; + var Item, m, i; if (!this.tmp.loadedItemIDs[id]) { this.tmp.loadedItemIDs[id] = true; } else { @@ -3029,13 +3001,23 @@ CSL.Engine.prototype.retrieveItem = function (id) { } } } - if (Item.language) { - var lst = Item.language.split("<"); - if (lst.length > 0) { - Item["language-name"] = lst[0]; + if (Item.language && Item.language.match(/[><]/)) { + var m = Item.language.match(/(.*?)([<>])(.*)/); + if (m[2] === "<") { + Item["language-name"] = m[1]; + Item["language-name-original"] = m[3]; + } else { + Item["language-name"] = m[3]; + Item["language-name-original"] = m[1]; } - if (lst.length === 2) { - Item["language-name-original"] = lst[1]; + if (this.opt.multi_layout) { + if (Item["language-name-original"]) { + Item.language = Item["language-name-original"]; + } + } else { + if (Item["language-name"]) { + Item.language = Item["language-name"]; + } } } if (Item.page) { @@ -3049,15 +3031,17 @@ CSL.Engine.prototype.retrieveItem = function (id) { if (this.opt.development_extensions.field_hack && Item.note) { CSL.parseNoteFieldHacks(Item, false, this.opt.development_extensions.allow_field_hack_date_override); } - for (var i = 1, ilen = CSL.DATE_VARIABLES.length; i < ilen; i += 1) { - var dateobj = Item[CSL.DATE_VARIABLES[i]]; - if (dateobj) { - if (this.opt.development_extensions.raw_date_parsing) { - if (dateobj.raw) { - dateobj = this.fun.dateparser.parseDateToObject(dateobj.raw); + for (var key in Item) { + if (CSL.DATE_VARIABLES.indexOf(key.replace(/^alt-/, "")) > -1) { + var dateobj = Item[key]; + if (dateobj) { + if (this.opt.development_extensions.raw_date_parsing) { + if (dateobj.raw) { + dateobj = this.fun.dateparser.parseDateToObject(dateobj.raw); + } } + Item[key] = this.dateParseArray(dateobj); } - Item[CSL.DATE_VARIABLES[i]] = this.dateParseArray(dateobj); } } if (this.opt.development_extensions.static_statute_locator) { @@ -3065,14 +3049,14 @@ CSL.Engine.prototype.retrieveItem = function (id) { var varname; var elements = ["type", "title", "jurisdiction", "genre", "volume", "container-title"]; var legislation_id = []; - for (i = 0, ilen = elements.length; i < ilen; i += 1) { + for (var i = 0, ilen = elements.length; i < ilen; i += 1) { varname = elements[i]; if (Item[varname]) { legislation_id.push(Item[varname]); } } elements = ["original-date", "issued"]; - for (i = 0, elements.length; i < ilen; i += 1) { + for (var i = 0, ilen=elements.length; i < ilen; i += 1) { varname = elements[i]; if (Item[varname] && Item[varname].year) { var value = Item[varname].year; @@ -3092,13 +3076,13 @@ CSL.Engine.prototype.retrieveItem = function (id) { _key: {} } } - ] + ]; if (Item.multi && Item.multi._keys && Item.multi._keys.authority) { Item.authority[0].multi._key = {}; for (var key in Item.multi._keys.authority) { Item.authority[0].multi._key[key] = { literal: Item.multi._keys.authority[key] - } + }; } } } @@ -3127,9 +3111,9 @@ CSL.Engine.prototype.retrieveItem = function (id) { normalizedKey = Item.title; } var jurisdiction = this.transform.loadAbbreviation(Item.jurisdiction, "title", normalizedKey, Item.type); - if (this.transform.abbrevs[jurisdiction]["title"]) { - if (this.transform.abbrevs[jurisdiction]["title"][normalizedKey]) { - Item["title-short"] = this.transform.abbrevs[jurisdiction]["title"][normalizedKey]; + if (this.transform.abbrevs[jurisdiction].title) { + if (this.transform.abbrevs[jurisdiction].title[normalizedKey]) { + Item["title-short"] = this.transform.abbrevs[jurisdiction].title[normalizedKey]; } } } @@ -3149,8 +3133,8 @@ CSL.Engine.prototype.retrieveItem = function (id) { } } } - if (Item["jurisdiction"]) { - Item["country"] = Item["jurisdiction"].split(":")[0]; + if (Item.jurisdiction) { + Item.country = Item.jurisdiction.split(":")[0]; } if (this.registry.refhash[id]) { if (JSON.stringify(this.registry.refhash[id]) != JSON.stringify(Item)) { @@ -3165,6 +3149,9 @@ CSL.Engine.prototype.retrieveItem = function (id) { } return this.registry.refhash[id]; }; +CSL.Engine.prototype.refetchItem = function (id) { + return this.registry.refhash[id]; +}; CSL.Engine.prototype.refetchItem = function (id) { return this.registry.refhash[id]; } @@ -3240,7 +3227,7 @@ CSL.Engine.prototype.remapSectionVariable = function (inputList) { item.label = ""; } } -} +}; CSL.Engine.prototype.setNumberLabels = function (Item) { if (Item.number && ["bill", "gazette", "legislation","regulation","treaty"].indexOf(Item.type) > -1 @@ -3256,12 +3243,10 @@ CSL.Engine.prototype.setNumberLabels = function (Item) { var firstword = value.split(/\s+/)[0]; var firstlabel = CSL.STATUTE_SUBDIV_STRINGS[firstword]; if (firstlabel) { - var m = value.match(CSL.STATUTE_SUBDIV_GROUPED_REGEX); var splt = value.split(CSL.STATUTE_SUBDIV_PLAIN_REGEX); if (splt.length > 1) { var lst = []; for (var j=1, jlen=splt.length; j < jlen; j += 1) { - var subdiv = m[j - 1].replace(/^\s*/, ""); lst.push(splt[j].replace(/\s*$/, "").replace(/^\s*/, "")); } value = lst.join(" "); @@ -3276,7 +3261,7 @@ CSL.Engine.prototype.setNumberLabels = function (Item) { this.tmp.shadow_numbers["number"].numeric = true; } } -} +}; CSL.substituteOne = function (template) { return function (state, list) { if (!list) { @@ -3351,12 +3336,9 @@ CSL.setDecorations = function (state, attributes) { return ret; }; CSL.Doppeler = function(rexStr, stringMangler) { - var mx, lst, len, pos, m, buf1, buf2, idx, ret, myret; - this.split = split; - this.join = join; var matchRex = new RegExp("(" + rexStr + ")", "g"); var splitRex = new RegExp(rexStr, "g"); - function split(str) { + this.split = function (str) { if (stringMangler) { str = stringMangler(str); } @@ -3382,9 +3364,9 @@ CSL.Doppeler = function(rexStr, stringMangler) { tags: match, strings: split, origStrings: split.slice() - } - } - function join(obj) { + }; + }; + this.join = function (obj) { var lst = obj.strings.slice(-1); for (var i=obj.tags.length-1; i>-1; i--) { lst.push(obj.tags[i]); @@ -3392,8 +3374,8 @@ CSL.Doppeler = function(rexStr, stringMangler) { } lst.reverse(); return lst.join(""); - } -} + }; +}; CSL.Engine.prototype.normalDecorIsOrphan = function (blob, params) { if (params[1] === "normal") { var use_param = false; @@ -3538,9 +3520,9 @@ CSL.Engine.prototype.getSortFunc = function () { a = a.split("-"); b = b.split("-"); if (a.length < b.length) { - return 1 + return 1; } else if (a.length > b.length) { - return -1 + return -1; } else { a = a.slice(-1)[0]; b = b.slice(-1)[0]; @@ -3738,7 +3720,7 @@ CSL.Output.Queue.prototype.pushFormats = function (tokenstore) { tokenstore.empty = this.empty; this.formats.push(tokenstore); }; -CSL.Output.Queue.prototype.popFormats = function (tokenstore) { +CSL.Output.Queue.prototype.popFormats = function () { this.formats.pop(); }; CSL.Output.Queue.prototype.startTag = function (name, token) { @@ -3755,8 +3737,8 @@ CSL.Output.Queue.prototype.endTag = function (name) { this.closeLevel(name); this.popFormats(); }; -CSL.Output.Queue.prototype.openLevel = function (token, ephemeral) { - var blob, curr, x, has_ephemeral; +CSL.Output.Queue.prototype.openLevel = function (token) { + var blob, curr; if ("object" === typeof token) { blob = new CSL.Blob(undefined, token); } else if ("undefined" === typeof token) { @@ -4082,7 +4064,7 @@ CSL.Output.Queue.prototype.clearlevel = function () { } }; CSL.Output.Queue.prototype.renderBlobs = function (blobs, delim, in_cite, parent) { - var state, ret, ret_last_char, use_delim, i, blob, pos, len, ppos, llen, pppos, lllen, res, str, params, txt_esc; + var state, ret, ret_last_char, use_delim, blob, pos, len, ppos, llen, str, params, txt_esc; txt_esc = CSL.getSafeEscape(this.state); if (!delim) { delim = ""; @@ -4213,16 +4195,12 @@ CSL.Output.Queue.adjust = function (punctInQuote) { var NO_SWAP_IN = { ";": true, ":": true - } + }; var NO_SWAP_OUT = { ".": true, "!": true, "?": true - } - this.upward = upward; - this.leftward = leftward; - this.downward = downward; - this.fix = fix; + }; var LtoR_MAP = { "!": { ".": "!", @@ -4266,7 +4244,7 @@ CSL.Output.Queue.adjust = function (punctInQuote) { ",": ";,", ".": ";" } - } + }; var SWAP_IN = {}; var SWAP_OUT = {}; var PUNCT = {}; @@ -4294,13 +4272,17 @@ CSL.Output.Queue.adjust = function (punctInQuote) { } function blobIsNumber(blob) { return ("number" === typeof blob.num || (blob.blobs && blob.blobs.length === 1 && "number" === typeof blob.blobs[0].num)); - }; + } function blobEndsInNumber(blob) { if ("number" === typeof blob.num) { return true; } - if (!blob.blobs || "object" !== typeof blob.blobs) return false; - if (blobEndsInNumber(blob.blobs[blob.blobs.length-1])) return true; + if (!blob.blobs || "object" !== typeof blob.blobs) { + return false; + } + if (blobEndsInNumber(blob.blobs[blob.blobs.length-1])) { + return true; + } } function blobHasDecorations(blob,includeQuotes) { var ret = false; @@ -4317,7 +4299,7 @@ CSL.Output.Queue.adjust = function (punctInQuote) { } } return ret; - }; + } function blobHasDescendantQuotes(blob) { if (blob.decorations) { for (var i=0,ilen=blob.decorations.length;i-1;i--) { - var endFlag = i === (parent.blobs.length-1); this.upward(parent.blobs[i]); var parentStrings = parent.strings; var childStrings = parent.blobs[i].strings; @@ -4469,7 +4454,7 @@ CSL.Output.Queue.adjust = function (punctInQuote) { } } } - }; + } function leftward (parent) { if ("object" !== typeof parent || "object" !== typeof parent.blobs || !parent.blobs.length) { return; @@ -4494,8 +4479,8 @@ CSL.Output.Queue.adjust = function (punctInQuote) { } } } - }; - function downward (parent, top) { + } + function downward (parent) { if (parent.blobs && "string" == typeof parent.blobs) { if (PUNCT[parent.strings.suffix.slice(0,1)] && parent.strings.suffix.slice(0,1) === parent.blobs.slice(-1)) { @@ -4525,8 +4510,6 @@ CSL.Output.Queue.adjust = function (punctInQuote) { parentStrings.delimiter = parentStrings.delimiter.slice(1); } } - var parentDecorations = blobHasDecorations(parent, true); - var parentIsNumber = blobIsNumber(parent); for (var i=parent.blobs.length-1;i>-1;i--) { var child = parent.blobs[i]; var childStrings = parent.blobs[i].strings; @@ -4588,11 +4571,11 @@ CSL.Output.Queue.adjust = function (punctInQuote) { } if (!childIsNumber && !childDecorations && PUNCT[childStrings.suffix.slice(0,1)] && "string" === typeof child.blobs) { - mergeChars(child, 'blobs', child, 'suffix') + mergeChars(child, 'blobs', child, 'suffix'); } this.downward(parent.blobs[i]); } - }; + } function swapToTheLeft (child) { var childChar = child.strings.suffix.slice(0,1); if ("string" === typeof child.blobs) { @@ -4649,8 +4632,12 @@ CSL.Output.Queue.adjust = function (punctInQuote) { } } return lastChar; - }; -} + } + this.upward = upward; + this.leftward = leftward; + this.downward = downward; + this.fix = fix; +}; CSL.Engine.Opt = function () { this.has_disambiguate = false; this.mode = "html"; @@ -4800,6 +4787,8 @@ CSL.Engine.Opt = function () { this.development_extensions.spoof_institutional_affiliations = false; this.development_extensions.force_jurisdiction = false; this.development_extensions.parse_names = true; + this.development_extensions.hanging_indent_legacy_number = true; + this.development_extensions.throw_on_empty = false; }; CSL.Engine.Tmp = function () { this.names_max = new CSL.Stack(); @@ -4858,9 +4847,12 @@ CSL.Engine.Tmp = function () { this.shadow_numbers = {}; this.authority_stop_last = 0; this.loadedItemIDs = {}; + this.condition_counter = 0; //incremented/decremented on ALL conditions + this.condition_lang_val_arr = []; + this.condition_lang_counter_arr = []; }; CSL.Engine.Fun = function (state) { - this.match = new CSL.Util.Match; + this.match = new CSL.Util.Match(); this.suffixator = new CSL.Util.Suffixator(CSL.SUFFIX_CHARS); this.romanizer = new CSL.Util.Romanizer(); this.ordinalizer = new CSL.Util.Ordinalizer(state); @@ -4874,6 +4866,8 @@ CSL.Engine.Build = function () { this.postponed_macro = false; this.layout_flag = false; this.name = false; + this.names_variables = [[]]; + this.name_label = [{}]; this.form = false; this.term = false; this.macro = {}; @@ -4889,6 +4883,7 @@ CSL.Engine.Build = function () { this.render_seen = false; }; CSL.Engine.Configure = function () { + this.tests = []; this.fail = []; this.succeed = []; }; @@ -4946,6 +4941,26 @@ CSL.Engine.CitationSort = function () { this.opt.topdecor = []; this.root = "citation"; }; +CSL.Engine.InText = function () { + this.opt = { + inheritedAttributes: {} + }; + this.tokens = []; + this.opt.collapse = []; + this.opt["disambiguate-add-names"] = false; + this.opt["disambiguate-add-givenname"] = false; + this.opt["disambiguate-add-year-suffix"] = false; + this.opt["givenname-disambiguation-rule"] = "by-cite"; + this.opt["near-note-distance"] = 5; + this.opt.topdecor = []; + this.opt.layout_decorations = []; + this.opt.layout_prefix = ""; + this.opt.layout_suffix = ""; + this.opt.layout_delimiter = ""; + this.opt.sort_locales = []; + this.opt.max_number_of_names = 0; + this.root = "intext"; +}; CSL.Engine.prototype.previewCitationCluster = function (citation, citationsPre, citationsPost, newMode) { var oldMode = this.opt.mode; this.setOutputFormat(newMode); @@ -5046,7 +5061,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, throw err; } citationByIndex.push(this.registry.citationreg.citationById[c[0]]); - citationById[c[0]] = this.registry.citationreg.citationById[c[0]];; + citationById[c[0]] = this.registry.citationreg.citationById[c[0]]; } citationByIndex.push(citation); citationById[citation.citationID] = citation; @@ -5194,7 +5209,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, item[1]["near-note"] = false; if (this.registry.citationreg.citationsByItemId[myid]) { if (this.opt.xclass === 'note' && this.opt.has_disambiguate) { - var oldCount = this.registry.registry[myid]["citation-count"] + var oldCount = this.registry.registry[myid]["citation-count"]; var newCount = this.registry.citationreg.citationsByItemId[myid].length; this.registry.registry[myid]["citation-count"] = this.registry.citationreg.citationsByItemId[myid].length; if ("number" === typeof oldCount) { @@ -5215,7 +5230,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, } } var oldlastid; - if ("undefined" === typeof first_ref[myid]) { + if ("undefined" === typeof first_ref[myid] && onecitation.properties.mode !== "author-only") { first_ref[myid] = onecitation.properties.noteIndex; if (this.registry.registry[myid]) { this.registry.registry[myid]['first-reference-note-number'] = onecitation.properties.noteIndex; @@ -5227,7 +5242,11 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, var suprame = false; if (j > 0) { try { - oldlastid = citations[j - 1].sortedItems.slice(-1)[0][1].id; + var old_last_id_offset = 1; + if (citations[j-1].properties.mode === "author-only" && j > 1) { + old_last_id_offset = 2; + } + oldlastid = citations[j - old_last_id_offset].sortedItems.slice(-1)[0][1].id; } catch (e) { var err = "CSL Error\n"; err += " " + e; @@ -5320,6 +5339,9 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, item[1].position = CSL.POSITION_SUBSEQUENT; } if (suprame || ibidme) { + if (onecitation.properties.mode === "author-only") { + item[1].position = CSL.POSITION_FIRST; + } if (first_ref[myid] != onecitation.properties.noteIndex) { item[1]["first-reference-note-number"] = first_ref[myid]; if (this.registry.registry[myid]) { @@ -5381,7 +5403,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, var ret = []; if (flag === CSL.PREVIEW) { try { - ret = this.process_CitationCluster.call(this, citation.sortedItems, citation.citationID); + ret = this.process_CitationCluster.call(this, citation.sortedItems, citation); } catch (e) { CSL.error("Error running CSL processor for preview: "+e); } @@ -5421,7 +5443,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, this.tmp.citation_id = "" + mycitation.citationID; obj = []; obj.push(mycitation.properties.index); - obj.push(this.process_CitationCluster.call(this, mycitation.sortedItems, mycitation.citationID)); + obj.push(this.process_CitationCluster.call(this, mycitation.sortedItems, mycitation)); obj.push(mycitation.citationID); ret.push(obj); } @@ -5432,7 +5454,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, this.tmp.citation_id = "" + citation.citationID; obj = []; obj.push(citationsPre.length); - obj.push(this.process_CitationCluster.call(this, sortedItems, citation.citationID)); + obj.push(this.process_CitationCluster.call(this, sortedItems, citation)); obj.push(citation.citationID); ret.push(obj); ret.sort(function (a, b) { @@ -5448,10 +5470,33 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, this.registry.return_data.citation_errors = this.tmp.citation_errors.slice(); return [this.registry.return_data, ret]; }; -CSL.Engine.prototype.process_CitationCluster = function (sortedItems, citationID) { - var str; +CSL.Engine.prototype.process_CitationCluster = function (sortedItems, citation) { + var str = ""; this.parallel.StartCitation(sortedItems); - str = CSL.getCitationCluster.call(this, sortedItems, citationID); + if (citation && citation.properties && citation.properties.mode === "composite") { + citation.properties.mode = "author-only"; + var firstChunk = CSL.getCitationCluster.call(this, sortedItems, citation); + citation.properties.mode = "suppress-author"; + var secondChunk = ""; + if (citation.properties.infix) { + this.output.append(citation.properties.infix); + secondChunk = this.output.string(this, this.output.queue); + if ("object" === typeof secondChunk) { + secondChunk = secondChunk.join(""); + } + } + var thirdChunk = CSL.getCitationCluster.call(this, sortedItems, citation); + citation.properties.mode = "composite"; + if (firstChunk && secondChunk && CSL.SWAPPING_PUNCTUATION.concat(["\u2019", "\'"]).indexOf(secondChunk[0]) > -1) { + firstChunk += secondChunk; + secondChunk = false; + } + str = [firstChunk, secondChunk, thirdChunk].filter(function(obj) { + return obj; + }).join(" "); + } else { + str = CSL.getCitationCluster.call(this, sortedItems, citation); + } return str; }; CSL.Engine.prototype.makeCitationCluster = function (rawList) { @@ -5494,11 +5539,11 @@ CSL.Engine.prototype.makeCitationCluster = function (rawList) { } this.tmp.citation_errors = []; this.parallel.StartCitation(inputList); - str = CSL.getCitationCluster.call(this, inputList); + var str = CSL.getCitationCluster.call(this, inputList); return str; }; CSL.getAmbiguousCite = function (Item, disambig, visualForm, item) { - var use_parallels, ret; + var ret; var flags = this.tmp.group_context.tip; var oldTermSiblingLayer = { term_intended: flags.term_intended, @@ -5510,7 +5555,7 @@ CSL.getAmbiguousCite = function (Item, disambig, visualForm, item) { condition: flags.condition, force_suppress: flags.force_suppress, done_vars: flags.done_vars.slice() - } + }; if (disambig) { this.tmp.disambig_request = disambig; } else { @@ -5536,6 +5581,7 @@ CSL.getAmbiguousCite = function (Item, disambig, visualForm, item) { this.tmp.area = "citation"; this.tmp.root = "citation"; this.parallel.use_parallels = (this.parallel.use_parallels === true || this.parallel.use_parallels === null) ? null : false; + var origSuppressDecorations = this.tmp.suppress_decorations; this.tmp.suppress_decorations = true; this.tmp.just_looking = true; CSL.getCite.call(this, Item, itemSupp, null, false); @@ -5552,7 +5598,7 @@ CSL.getAmbiguousCite = function (Item, disambig, visualForm, item) { } var ret = this.output.string(this, this.output.queue); this.tmp.just_looking = false; - this.tmp.suppress_decorations = false; + this.tmp.suppress_decorations = origSuppressDecorations; this.parallel.use_parallels = this.parallel.use_parallels === null ? true : false; this.tmp.group_context.replace(oldTermSiblingLayer); return ret; @@ -5584,8 +5630,20 @@ CSL.getSpliceDelimiter = function (last_locator, last_collapsed, pos) { } return this.tmp.splice_delimiter; }; -CSL.getCitationCluster = function (inputList, citationID) { - var result, objects, myparams, len, pos, item, last_collapsed, params, empties, composite, compie, myblobs, Item, llen, ppos, obj, preceding_item, txt_esc, error_object; +CSL.getCitationCluster = function (inputList, citation) { + var result, objects, myparams, len, pos, item, last_collapsed, params, empties, composite, compie, myblobs, Item, llen, ppos, obj, preceding_item, txt_esc, error_object, citationID, authorOnly, suppressAuthor; + var citation_prefix = ""; + this.output.checkNestedBrace = new CSL.checkNestedBrace(this); + if (citation) { + citationID = citation.citationID; + authorOnly = citation.properties.mode === "author-only" ? !!citation.properties.mode : false; + if (this.opt.xclass !== "note") { + suppressAuthor = citation.properties.mode === "suppress-author" ? !!citation.properties.mode : false; + } + if (citation.properties.prefix) { + citation_prefix = CSL.checkPrefixSpaceAppend(this, citation.properties.prefix); + } + } inputList = inputList ? inputList : []; this.tmp.last_primary_names_string = false; txt_esc = CSL.getSafeEscape(this); @@ -5598,8 +5656,7 @@ CSL.getCitationCluster = function (inputList, citationID) { this.tmp.last_years_used = []; this.tmp.backref_index = []; this.tmp.cite_locales = []; - this.output.checkNestedBrace = new CSL.checkNestedBrace(this); - var use_layout_prefix = this.output.checkNestedBrace.update(this.citation.opt.layout_prefix); + var use_layout_prefix = this.output.checkNestedBrace.update(this.citation.opt.layout_prefix + citation_prefix); var suppressTrailingPunctuation = false; if (this.opt.xclass === "note" && this.citation.opt.suppressTrailingPunctuation) { suppressTrailingPunctuation = true; @@ -5656,6 +5713,15 @@ CSL.getCitationCluster = function (inputList, citationID) { } myparams = []; len = inputList.length; + if (inputList[0] && inputList[0][1]) { + if (authorOnly) { + delete inputList[0][1]["suppress-author"]; + inputList[0][1]["author-only"] = true; + } else if (suppressAuthor) { + delete inputList[0][1]["author-only"]; + inputList[0][1]["suppress-author"] = true; + } + } for (pos = 0; pos < len; pos += 1) { Item = inputList[pos][0]; item = inputList[pos][1]; @@ -5715,17 +5781,18 @@ CSL.getCitationCluster = function (inputList, citationID) { params.suppress_decorations = this.tmp.suppress_decorations; params.have_collapsed = this.tmp.have_collapsed; myparams.push(params); + if (item["author-only"]) { + break; + } } this.tmp.has_purged_parallel = false; this.parallel.PruneOutputQueue(this); empties = 0; myblobs = this.output.queue.slice(); - var fakeblob = { - strings: { - suffix: this.citation.opt.layout_suffix, - delimiter: this.citation.opt.layout_delimiter - } - }; + var citation_suffix = ""; + if (citation) { + citation_suffix = CSL.checkSuffixSpacePrepend(this, citation.properties.suffix); + } var suffix = this.citation.opt.layout_suffix; var last_locale = this.tmp.cite_locales[this.tmp.cite_locales.length - 1]; if (last_locale && this.tmp.cite_affixes[this.tmp.area][last_locale] && this.tmp.cite_affixes[this.tmp.area][last_locale].suffix) { @@ -5734,14 +5801,7 @@ CSL.getCitationCluster = function (inputList, citationID) { if (CSL.TERMINAL_PUNCTUATION.slice(0, -1).indexOf(suffix.slice(0, 1)) > -1) { suffix = suffix.slice(0, 1); } - var delimiter = this.citation.opt.layout_delimiter; - if (!delimiter) { - delimiter = ""; - } - if (CSL.TERMINAL_PUNCTUATION.slice(0, -1).indexOf(delimiter.slice(0, 1)) > -1) { - delimiter = delimiter.slice(0, 1); - } - suffix = this.output.checkNestedBrace.update(suffix); + suffix = this.output.checkNestedBrace.update(citation_suffix + suffix); for (var i=0,ilen=this.output.queue.length;i 0) { + this.tmp.area = "intext"; + } this.tmp.cite_renders_content = false; + this.tmp.probably_rendered_something = false; this.parallel.StartCite(Item, item, prevItemID); CSL.citeStart.call(this, Item, item, blockShadowNumberReset); next = 0; @@ -5883,6 +5966,7 @@ CSL.getCite = function (Item, item, prevItemID, blockShadowNumberReset) { this.tmp.bibliography_errors.push(error_object); } } + this.tmp.area = areaOrig; return "" + Item.id; }; CSL.citeStart = function (Item, item, blockShadowNumberReset) { @@ -5982,7 +6066,7 @@ CSL.citeEnd = function (Item, item) { this.tmp.issued_date.list.push(buf.pop()); } if (this.parallel.use_parallels) { - this.parallel.cite["issued"] = false; + this.parallel.cite.issued = false; } } this.tmp.issued_date = false; @@ -5991,6 +6075,28 @@ CSL.citeEnd = function (Item, item) { CSL.Engine.prototype.makeBibliography = function (bibsection) { var debug, ret, params, maxoffset, item, len, pos, tok, tokk, tokkk, entry_ids, entry_strings; debug = false; + if (!bibsection && (this.bibliography.opt.exclude_types || this.bibliography.opt.exclude_with_fields)) { + bibsection = { + exclude: [] + }; + if (this.bibliography.opt.exclude_types) { + for (var i in this.bibliography.opt.exclude_types) { + var val = this.bibliography.opt.exclude_types[i]; + bibsection.exclude.push({ + field: "type", + value: val + }); + } + } + if (this.bibliography.opt.exclude_with_fields) { + for (var i in this.bibliography.opt.exclude_with_fields) { + var field = this.bibliography.opt.exclude_with_fields[i]; + bibsection.exclude.push({ + field: field, value: true + }); + } + } + } if (!this.bibliography.tokens.length) { return false; } @@ -6061,15 +6167,20 @@ CSL.getBibliographyEntries = function (bibsection) { return false; } function eval_spec(a, b) { - if ((a === "none" || !a) && !b) { - return true; - } - if ("string" === typeof b) { - return eval_string(a, b); - } else if (!b) { - return false; + if ("boolean" === typeof a || !a) { + if (a) { + return !!b; + } else { + return !b; + } } else { - return eval_list(a, b); + if ("string" === typeof b) { + return eval_string(a, b); + } else if (!b) { + return false; + } else { + return eval_list(a, b); + } } } skips = {}; @@ -6295,7 +6406,7 @@ CSL.Engine.prototype.rebuildProcessorState = function (citations, mode, uncitedI this.updateUncitedItems(uncitedItemIDs); this.setOutputFormat(oldMode); return ret; -} +}; CSL.Engine.prototype.restoreProcessorState = function (citations) { var i, ilen, j, jlen, item, Item, newitem, citationList, itemList, sortedItems; citationList = []; @@ -6395,7 +6506,6 @@ CSL.Engine.prototype.updateItems = function (idList, nosort, rerun_ambigs, impli }; CSL.Engine.prototype.updateUncitedItems = function (idList, nosort) { var idHash; - var debug = false; var oldArea = this.tmp.area; var oldRoot = this.tmp.root; var oldExtension = this.tmp.extension; @@ -6403,8 +6513,8 @@ CSL.Engine.prototype.updateUncitedItems = function (idList, nosort) { nosort = true; } this.tmp.area = "citation"; - this.tmp.root = "citation" - this.tmp.extension = "" + this.tmp.root = "citation"; + this.tmp.extension = ""; this.tmp.loadedItemIDs = {}; if (!idList) { idList = []; @@ -6509,7 +6619,7 @@ CSL.Engine.prototype.localeConfigure = function (langspec, beShy) { } }; CSL.Engine.prototype.localeSet = function (myxml, lang_in, lang_out) { - var blob, locale, nodes, attributes, pos, ppos, term, form, termname, styleopts, attr, date, attrname, len, genderform, target, i, ilen; + var blob, locale, nodes, attributes, pos, term, form, termname, styleopts, date, attrname, len, genderform, target, i, ilen; lang_in = lang_in.replace("_", "-"); lang_out = lang_out.replace("_", "-"); if (this.opt.development_extensions.normalize_lang_keys_to_lowercase) { @@ -6566,7 +6676,6 @@ CSL.Engine.prototype.localeSet = function (myxml, lang_in, lang_out) { termname = "sub-verbo"; } if (termname.slice(0,7) === "ordinal") { - var termstring = myxml.getNodeValue(term); if (termname === "ordinal") { ordinals101_toggle = true; } else { @@ -6726,7 +6835,7 @@ CSL.getLocaleNames = function (myxml, preferredLocale) { function extendLocaleList(localeList, locale) { var forms = ["base", "best"]; if (locale) { - normalizedLocale = CSL.localeResolve(locale); + var normalizedLocale = CSL.localeResolve(locale); for (var i=0,ilen=forms.length;i 1 - && publisher_lst.length === publisher_place_lst.length) { - state.publisherOutput = new CSL.PublisherOutput(state, this); - state.publisherOutput["publisher-list"] = publisher_lst; - state.publisherOutput["publisher-place-list"] = publisher_place_lst; + if (this.strings["subgroup-delimiter"]) { + func = function (state, Item) { + if (Item.publisher && Item["publisher-place"]) { + var publisher_lst = Item.publisher.split(/;\s*/); + var publisher_place_lst = Item["publisher-place"].split(/;\s*/); + if (publisher_lst.length > 1 + && publisher_lst.length === publisher_place_lst.length) { + state.publisherOutput = new CSL.PublisherOutput(state, this); + state.publisherOutput["publisher-list"] = publisher_lst; + state.publisherOutput["publisher-place-list"] = publisher_place_lst; + } } - } - }; - this.execs.push(func); + }; + this.execs.push(func); + } } if (this.juris) { - for (var x=0,xlen=target.length;x 0) { + var counter = state.tmp.condition_lang_counter_arr.slice(-1)[0]; + if (counter === state.tmp.condition_counter) { + state.opt.lang = state.tmp.condition_lang_val_arr.pop(); + state.tmp.condition_lang_counter_arr.pop(); + } + } if (this.locale_default) { state.output.current.value().old_locale = this.locale_default; state.output.closeLevel("empty"); @@ -7507,6 +7644,7 @@ CSL.Conditions.Engine = function (state, token) { this.state = state; }; CSL.Conditions.Engine.prototype.addTest = function (test) { + this.token.tests ? {} : this.token.tests = []; this.token.tests.push(test); }; CSL.Conditions.Engine.prototype.addMatch = function (match) { @@ -7516,7 +7654,7 @@ CSL.Conditions.Engine.prototype.matchCombine = function () { this.token.test = this.state.fun.match[this.token.match](this.token, this.state, this.token.tests); }; CSL.Node.info = { - build: function (state, target) { + build: function (state) { if (this.tokentype === CSL.START) { state.build.skip = "info"; } else { @@ -7527,13 +7665,12 @@ CSL.Node.info = { CSL.Node.institution = { build: function (state, target) { if ([CSL.SINGLETON, CSL.START].indexOf(this.tokentype) > -1) { - var func = function (state, Item) { + var func = function (state) { if ("string" === typeof this.strings.delimiter) { state.tmp.institution_delimiter = this.strings.delimiter; } else { state.tmp.institution_delimiter = state.tmp.name_delimiter; } - var myand, and_default_prefix, and_suffix; if ("text" === state.inheritOpt(this, "and")) { this.and_term = state.getTerm("and", "long", 0); } else if ("symbol" === state.inheritOpt(this, "and")) { @@ -7591,7 +7728,7 @@ CSL.Node.institution = { } target.push(this); }, - configure: function (state, pos) { + configure: function (state) { if ([CSL.SINGLETON, CSL.START].indexOf(this.tokentype) > -1) { state.build.has_institution = true; } @@ -7602,16 +7739,16 @@ CSL.Node["institution-part"] = { var func; if ("long" === this.strings.name) { if (this.strings["if-short"]) { - func = function (state, Item) { + func = function (state) { state.nameOutput.institutionpart["long-with-short"] = this; }; } else { - func = function (state, Item) { + func = function (state) { state.nameOutput.institutionpart["long"] = this; }; } } else if ("short" === this.strings.name) { - func = function (state, Item) { + func = function (state) { state.nameOutput.institutionpart["short"] = this; }; } @@ -7622,19 +7759,19 @@ CSL.Node["institution-part"] = { CSL.Node.key = { build: function (state, target) { target = state[state.build.root + "_sort"].tokens; - var func, i, ilen; + var func; var debug = false; var start_key = new CSL.Token("key", CSL.START); state.tmp.root = state.build.root; start_key.strings["et-al-min"] = state.inheritOpt(this, "et-al-min"); start_key.strings["et-al-use-first"] = state.inheritOpt(this, "et-al-use-first"); start_key.strings["et-al-use-last"] = state.inheritOpt(this, "et-al-use-last"); - func = function (state, Item) { + func = function (state) { state.tmp.done_vars = []; }; start_key.execs.push(func); state.opt.citation_number_sort_direction = this.strings.sort_direction; - func = function (state, Item) { + func = function (state) { state.output.openLevel("empty"); }; start_key.execs.push(func); @@ -7650,7 +7787,7 @@ CSL.Node.key = { if (CSL.DATE_VARIABLES.indexOf(this.variables[0]) > -1) { state.build.date_key = true; } - func = function (state, Item) { + func = function (state) { state.tmp.sort_key_flag = true; if (state.inheritOpt(this, "et-al-min")) { state.tmp["et-al-min"] = state.inheritOpt(this, "et-al-min"); @@ -7698,8 +7835,7 @@ CSL.Node.key = { single_text.dateparts = this.dateparts; if (CSL.NUMERIC_VARIABLES.indexOf(variable) > -1) { func = function (state, Item) { - var num, m; - num = false; + var num = false; if ("citation-number" === variable) { num = state.registry.registry[Item.id].seq.toString(); } else { @@ -7739,7 +7875,7 @@ CSL.Node.key = { CSL.expandMacro.call(state, token, target); } var end_key = new CSL.Token("key", CSL.END); - func = function (state, Item) { + func = function (state) { var keystring = state.output.string(state, state.output.queue); if (state.sys.normalizeUnicode) { keystring = state.sys.normalizeUnicode(keystring); @@ -7766,12 +7902,12 @@ CSL.Node.key = { } var key = CSL.Util.padding("" + year_suffix); state[state.tmp.area].keys.push(key); - } + }; end_key.execs.push(func); } state.build.date_key = false; } - func = function (state, Item) { + func = function (state) { state.tmp["et-al-min"] = undefined; state.tmp["et-al-use-first"] = undefined; state.tmp["et-al-use-last"] = undefined; @@ -7783,11 +7919,7 @@ CSL.Node.key = { }; CSL.Node.label = { build: function (state, target) { - var debug = false; if (this.strings.term) { - var plural = false; - if (!this.strings.form) { - } var func = function (state, Item, item) { var termtxt = CSL.evaluateLabel(this, state, Item, item); if (item && this.strings.term === "locator") { @@ -7816,22 +7948,20 @@ CSL.Node.label = { if (!this.strings.form) { this.strings.form = "long"; } - var namevars = state.build.names_variables.slice(-1)[0]; - if (!state.build.name_label) { - state.build.name_label = {}; - } + var namevars = state.build.names_variables[state.build.names_variables.length-1]; + var namelabels = state.build.name_label[state.build.name_label.length-1]; for (var i = 0, ilen = namevars.length; i < ilen; i += 1) { - if (!state.build.name_label[namevars[i]]) { - state.build.name_label[namevars[i]] = {}; + if (!namelabels[namevars[i]]) { + namelabels[namevars[i]] = {}; } } if (!state.build.name_flag) { for (var i = 0, ilen = namevars.length; i < ilen; i += 1) { - state.build.name_label[namevars[i]].before = this; + namelabels[namevars[i]].before = this; } } else { for (var i = 0, ilen = namevars.length; i < ilen; i += 1) { - state.build.name_label[namevars[i]].after = this; + namelabels[namevars[i]].after = this; } } } @@ -7844,8 +7974,7 @@ CSL.Node.layout = { function setSuffix() { if (state.build.area === "bibliography") { suffix_token = new CSL.Token("text", CSL.SINGLETON); - func = function(state, Item, item) { - var last_locale = state.tmp.cite_locales[state.tmp.cite_locales.length - 1]; + func = function(state) { var suffix; if (state.tmp.cite_affixes[state.tmp.area][state.tmp.last_cite_locale]) { suffix = state.tmp.cite_affixes[state.tmp.area][state.tmp.last_cite_locale].suffix; @@ -7878,7 +8007,7 @@ CSL.Node.layout = { && !state.tmp.just_looking && Item.system_id && state.tmp.area === "citation") { - cite_entry = new CSL.Token("group", CSL.START); + var cite_entry = new CSL.Token("group", CSL.START); cite_entry.decorations = [["@cite", "entry"]]; state.output.startTag("cite_entry", cite_entry); state.output.current.value().item_id = Item.system_id; @@ -7887,7 +8016,7 @@ CSL.Node.layout = { state.output.current.value().suffix_txt = item.suffix_txt; } } - } + }; this.execs.push(func); } if (this.tokentype === CSL.START && !state.tmp.cite_affixes[state.build.area]) { @@ -7904,11 +8033,11 @@ CSL.Node.layout = { state.tmp.rendered_name = false; }; this.execs.push(func); - func = function (state, Item) { + func = function (state) { state.tmp.sort_key_flag = false; }; this.execs.push(func); - func = function (state, Item) { + func = function (state) { state.tmp.nameset_counter = 0; }; this.execs.push(func); @@ -7922,7 +8051,7 @@ CSL.Node.layout = { } } state.output.openLevel(tok); - } + }; this.execs.push(func); target.push(this); if (state.opt.development_extensions.rtl_support && false) { @@ -7932,27 +8061,12 @@ CSL.Node.layout = { if (state.build.area === "citation") { prefix_token = new CSL.Token("text", CSL.SINGLETON); func = function (state, Item, item) { - var sp; if (item && item.prefix) { - sp = ""; - var test_prefix = item.prefix.replace(/<[^>]+>/g, "").replace(/["'\u201d\u2019\u00bb\u202f\u00a0 ]+$/g,""); - var test_char = test_prefix.slice(-1); - if (test_prefix.match(CSL.ENDSWITH_ROMANESQUE_REGEXP)) { - sp = " "; - } else if (CSL.TERMINAL_PUNCTUATION.slice(0,-1).indexOf(test_char) > -1) { - sp = " "; - } else if (test_char.match(/[\)\],0-9]/)) { - sp = " "; - } - var ignorePredecessor = false; - if (CSL.TERMINAL_PUNCTUATION.slice(0,-1).indexOf(test_char) > -1 && item.prefix.trim().indexOf(" ") > -1) { - state.tmp.term_predecessor = false; - ignorePredecessor = true; - } - var prefix = (item.prefix + sp).replace(/\s+/g, " "); + var prefix = CSL.checkPrefixSpaceAppend(state, item.prefix); if (!state.tmp.just_looking) { prefix = state.output.checkNestedBrace.update(prefix); } + var ignorePredecessor = CSL.checkIgnorePredecessor(state, prefix); state.output.append(prefix, this, false, ignorePredecessor); } }; @@ -8033,22 +8147,17 @@ CSL.Node.layout = { func = function (state, Item, item) { var sp; if (item && item.suffix) { - sp = ""; - if (item.suffix.match(CSL.STARTSWITH_ROMANESQUE_REGEXP) - || ['[','('].indexOf(item.suffix.slice(0,1)) > -1) { - sp = " "; - } - var suffix = item.suffix; + var suffix = CSL.checkSuffixSpacePrepend(state, item.suffix); if (!state.tmp.just_looking) { suffix = state.output.checkNestedBrace.update(suffix); } - state.output.append((sp + suffix), this); + state.output.append((suffix), this); } }; suffix_token.execs.push(func); target.push(suffix_token); } - func = function (state, Item) { + func = function (state) { state.output.closeLevel(); }; this.execs.push(func); @@ -8060,7 +8169,7 @@ CSL.Node.layout = { && state.tmp.area === "citation") { state.output.endTag(); // closes citation link wrapper } - } + }; this.execs.push(func); target.push(this); state.build.layout_flag = false; @@ -8070,9 +8179,130 @@ CSL.Node.layout = { } }; CSL.Node.macro = { - build: function (state, target) {} + build: function () {} }; -CSL.NameOutput = function(state, Item, item, variables) { +CSL.Node.alternative = { + build: function (state, target) { + if (this.tokentype === CSL.START) { + var choose_tok = new CSL.Token("choose", CSL.START); + CSL.Node["choose"].build.call(choose_tok, state, target); + var if_tok = new CSL.Token("if", CSL.START); + CSL.Attributes["@alternative-node-internal"].call(if_tok, state); + CSL.Node["if"].build.call(if_tok, state, target); + var func = function(state, Item) { + state.tmp.oldItem = Item; + state.tmp.oldLang = state.opt.lang; + state.tmp.abort_alternative = true; + if (Item["language-name"] && Item["language-name-original"]) { + var newItem = JSON.parse(JSON.stringify(Item)); + newItem.language = newItem["language-name"]; + var langspec = CSL.localeResolve(newItem.language, state.opt["default-locale"][0]); + if (state.opt.multi_layout) { + for (var i in state.opt.multi_layout) { + var locale_list = state.opt.multi_layout[i]; + var gotlang = false; + for (var j in locale_list) { + var tryspec = locale_list[j]; + if (langspec.best === tryspec.best || langspec.base === tryspec.base || langspec.bare === tryspec.bare) { + gotlang = locale_list[0].best; + break; + } + } + if (!gotlang) { + gotlang = state.opt["default-locale"][0]; + } + state.opt.lang = gotlang; + } + } + for (var key in newItem) { + if (["id", "type", "language", "multi"].indexOf(key) === -1 && key.slice(0, 4) !== "alt-") { + if (newItem.multi && newItem.multi._keys[key]) { + var deleteme = true; + for (var lang in newItem.multi._keys[key]) { + if (langspec.bare === lang.replace(/^([a-zA-Z]+).*/, "$1")) { + deleteme = false; + break; + } + } + if (deleteme) { + delete newItem[key]; + } + } else { + delete newItem[key]; + } + } + } + for (var key in newItem) { + if (key.slice(0, 4) === "alt-") { + newItem[key.slice(4)] = newItem[key]; + state.tmp.abort_alternative = false; + } else { + if (newItem.multi && newItem.multi._keys) { + if (!newItem["alt-" + key] && newItem.multi._keys[key]) { + if (newItem.multi._keys[key][langspec.best]) { + newItem[key] = newItem.multi._keys[key][langspec.best]; + state.tmp.abort_alternative = false; + } else if (newItem.multi._keys[key][langspec.base]) { + newItem[key] = newItem.multi._keys[key][langspec.base]; + state.tmp.abort_alternative = false; + } else if (newItem.multi._keys[key][langspec.bare]) { + newItem[key] = newItem.multi._keys[key][langspec.bare]; + state.tmp.abort_alternative = false; + } + } + } + } + } + } + state.output.openLevel(this); + state.registry.refhash[Item.id] = newItem; + state.nameOutput = new CSL.NameOutput(state, newItem); + }; + this.execs.push(func); + target.push(this); + var choose_tok = new CSL.Token("choose", CSL.START); + CSL.Node["choose"].build.call(choose_tok, state, target); + var if_tok = new CSL.Token("if", CSL.START); + CSL.Attributes["@alternative-node-internal"].call(if_tok, state); + var func = function(state) { + state.tmp.abort_alternative = true; + } + if_tok.execs.push(func); + CSL.Node["if"].build.call(if_tok, state, target); + } else if (this.tokentype === CSL.END) { + var if_tok = new CSL.Token("if", CSL.END); + CSL.Node["if"].build.call(if_tok, state, target); + var choose_tok = new CSL.Token("choose", CSL.END); + CSL.Node["choose"].build.call(choose_tok, state, target); + var func = function(state, Item) { + state.output.closeLevel(); + state.registry.refhash[Item.id] = state.tmp.oldItem; + state.opt.lang = state.tmp.oldLang; + state.nameOutput = new CSL.NameOutput(state, state.tmp.oldItem); + state.tmp.abort_alternative = false; + }; + this.execs.push(func); + target.push(this); + var if_tok = new CSL.Token("if", CSL.END); + CSL.Node["if"].build.call(if_tok, state, target); + var choose_tok = new CSL.Token("choose", CSL.END); + CSL.Node["choose"].build.call(choose_tok, state, target); + } + } +}; +CSL.Node["alternative-text"] = { + build: function (state, target) { + if (this.tokentype === CSL.SINGLETON) { + var func = function(state, Item) { + var Item = state.refetchItem(Item.id); + CSL.getCite.call(state, Item); + }; + this.execs.push(func); + } + target.push(this); + } +}; +CSL.NameOutput = function(state, Item, item) { this.debug = false; this.state = state; this.Item = Item; @@ -8083,6 +8313,7 @@ CSL.NameOutput = function(state, Item, item, variables) { this._please_chop = false; }; CSL.NameOutput.prototype.init = function (names) { + this.requireMatch = names.requireMatch; if (this.state.tmp.term_predecessor) { this.state.tmp.subsequent_author_substitute_ok = false; } @@ -8111,8 +8342,22 @@ CSL.NameOutput.prototype.init = function (names) { if (!this.state.tmp.value.length) { return; } + var checkCommonTerm = this.checkCommonAuthor(this.requireMatch); + if (checkCommonTerm) { + this.state.tmp.can_substitute.pop(); + this.state.tmp.can_substitute.push(true); + for (var i in this.variables) { + var idx = this.state.tmp.done_vars.indexOf(this.variables[i]); + if (idx > -1) { + this.state.tmp.done_vars = this.state.tmp.done_vars.slice(0, idx).concat(this.state.tmp.done_vars.slice(i+1)); + } + } + this.state.tmp.common_term_match_fail = true; + this.variables = []; + } }; CSL.NameOutput.prototype.reinit = function (names, labelVariable) { + this.requireMatch = names.requireMatch; this.labelVariable = labelVariable; if (this.state.tmp.can_substitute.value()) { this.nameset_offset = 0; @@ -8129,6 +8374,18 @@ CSL.NameOutput.prototype.reinit = function (names, labelVariable) { } this.state.tmp.value = oldval; } + var checkCommonTerm = this.checkCommonAuthor(this.requireMatch); + if (checkCommonTerm) { + this.state.tmp.can_substitute.pop(); + this.state.tmp.can_substitute.push(true); + for (var i in this.variables) { + var idx = this.state.tmp.done_vars.indexOf(this.variables[i]); + if (idx > -1) { + this.state.tmp.done_vars = this.state.tmp.done_vars.slice(0, idx).concat(this.state.tmp.done_vars.slice(i+1)); + } + } + this.variables = []; + } }; CSL.NameOutput.prototype.outputNames = function () { var i, ilen; @@ -8175,7 +8432,7 @@ CSL.NameOutput.prototype.outputNames = function () { return; } this.setEtAlParameters(); - this.setCommonTerm(); + this.setCommonTerm(this.requireMatch); this.state.tmp.name_node = {}; this.state.tmp.name_node.children = []; this.renderAllNames(); @@ -8215,14 +8472,17 @@ CSL.NameOutput.prototype.outputNames = function () { for (i = 0, ilen = blob_list.length; i < ilen; i += 1) { this.state.output.append(blob_list[i], "literal", true); } + if (!this.state.tmp.just_looking && blob_list.length > 0) { + this.state.tmp.probably_rendered_something = true; + } this.state.output.closeLevel("empty"); var blob = this.state.output.pop(); + this.state.tmp.name_node.top = blob; var namesToken = CSL.Util.cloneToken(this.names); this.state.output.append(blob, namesToken); if (this.state.tmp.term_predecessor_name) { this.state.tmp.term_predecessor = true; } - this.state.tmp.name_node.top = this.state.output.current.value(); if (variables[0] !== "authority") { var name_node_string = []; var nameobjs = this.Item[variables[0]]; @@ -8320,11 +8580,13 @@ CSL.NameOutput.prototype._buildLabel = function (term, plural, position, v) { }; CSL.NameOutput.prototype._collapseAuthor = function () { var myqueue, mystr, oldchars; + if (this.state.tmp.name_node.top.blobs.length === 0) { + return; + } if (this.nameset_base === 0 && this.Item[this.variables[0]] && !this._first_creator_variable) { this._first_creator_variable = this.variables[0]; } - if ((this.item && this.item["suppress-author"] && this._first_creator_variable == this.variables[0]) - || (this.state[this.state.tmp.area].opt.collapse + if ((this.state[this.state.tmp.area].opt.collapse && this.state[this.state.tmp.area].opt.collapse.length) || (this.state[this.state.tmp.area].opt.cite_group_delimiter && this.state[this.state.tmp.area].opt.cite_group_delimiter.length)) { @@ -8338,7 +8600,7 @@ CSL.NameOutput.prototype._collapseAuthor = function () { this.state.tmp.offset_characters = oldchars; this.state.registry.authorstrings[this.Item.id] = mystr; } else if (!this.state.tmp.just_looking - && !this.state.tmp.suppress_decorations && (this.item["suppress-author"] || (this.state[this.state.tmp.area].opt.collapse && this.state[this.state.tmp.area].opt.collapse.length) || this.state[this.state.tmp.area].opt.cite_group_delimiter && this.state[this.state.tmp.area].opt.cite_group_delimiter)) { + && !this.state.tmp.suppress_decorations && ((this.state[this.state.tmp.area].opt.collapse && this.state[this.state.tmp.area].opt.collapse.length) || this.state[this.state.tmp.area].opt.cite_group_delimiter && this.state[this.state.tmp.area].opt.cite_group_delimiter)) { mystr = ""; myqueue = this.state.tmp.name_node.top.blobs.slice(-1)[0].blobs; oldchars = this.state.tmp.offset_characters; @@ -8522,7 +8784,7 @@ CSL.NameOutput.prototype.divideAndTransliterateNames = function () { } }; CSL.NameOutput.prototype._normalizeVariableValue = function (Item, variable) { - var names, name, i, ilen; + var names; if ("string" === typeof Item[variable] || "number" === typeof Item[variable]) { CSL.debug("name variable \"" + variable + "\" is string or number, not array. Attempting to fix."); names = [{literal: Item[variable] + ""}]; @@ -8567,7 +8829,9 @@ CSL.NameOutput.prototype._getFreeters = function (v, values) { CSL.NameOutput.prototype._getPersonsAndInstitutions = function (v, values) { this.persons[v] = []; this.institutions[v] = []; - if (!this.state.opt.development_extensions.spoof_institutional_affiliations) return; + if (!this.state.opt.development_extensions.spoof_institutional_affiliations) { + return; + } var persons = []; var has_affiliates = false; var first = true; @@ -8687,7 +8951,7 @@ CSL.NameOutput.prototype._joinEllipsis = function (blobs, tokenname) { CSL.NameOutput.prototype._joinAnd = function (blobs, tokenname) { return this._join(blobs, this.state.inheritOpt(this[tokenname], "delimiter", (tokenname + "-delimiter"), ", "), this[tokenname].and.single, this[tokenname].and.multiple, tokenname); }; -CSL.NameOutput.prototype._join = function (blobs, delimiter, single, multiple, tokenname) { +CSL.NameOutput.prototype._join = function (blobs, delimiter, single, multiple) { var i, ilen; if (!blobs) { return false; @@ -8746,13 +9010,45 @@ CSL.NameOutput.prototype._getToken = function (tokenname) { } return token; }; +CSL.NameOutput.prototype.checkCommonAuthor = function(requireMatch) { + if (!requireMatch) { + return false; + } + var common_term = false; + if (this.variables.length === 2) { + var variables = this.variables; + var varnames = variables.slice(); + varnames.sort(); + common_term = varnames.join(""); + } + if (!common_term) { + return false; + } + var has_term = false; + if (this.state.locale[this.state.opt.lang].terms[common_term]) { + has_term = true; + } + if (!has_term) { + this.state.tmp.done_vars.push(this.variables[0]); + this.state.tmp.done_vars.push(this.variables[1]); + return false; + } + var firstSet = this.Item[this.variables[0]]; + var secondSet = this.Item[this.variables[1]]; + var perfectMatch = this._compareNamesets(firstSet, secondSet); + if (perfectMatch === true) { + this.state.tmp.done_vars.push(this.variables[0]); + this.state.tmp.done_vars.push(this.variables[1]); + } + return !perfectMatch; +}; CSL.NameOutput.prototype.setCommonTerm = function () { var variables = this.variables; var varnames = variables.slice(); varnames.sort(); this.common_term = varnames.join(""); if (!this.common_term) { - return false; + return; } var has_term = false; if (this.label && this.label[this.variables[0]]) { @@ -8761,7 +9057,7 @@ CSL.NameOutput.prototype.setCommonTerm = function () { } else if (this.label[this.variables[0]].after) { has_term = this.state.getTerm(this.common_term, this.label[this.variables[0]].after.strings.form, 0); } - } + } if (!this.state.locale[this.state.opt.lang].terms[this.common_term] || !has_term || this.variables.length < 2) { @@ -8794,11 +9090,10 @@ CSL.NameOutput.prototype.setCommonTerm = function () { } }; CSL.NameOutput.prototype._compareNamesets = function (base_nameset, nameset) { - if (base_nameset.length !== nameset.length) { + if (!base_nameset || !nameset || base_nameset.length !== nameset.length) { return false; } for (var i = 0, ilen = nameset.length; i < ilen; i += 1) { - var name = nameset[i]; for (var j = 0, jlen = CSL.NAME_PARTS.length; j < jlen; j += 1) { var part = CSL.NAME_PARTS[j]; if (!base_nameset[i] || base_nameset[i][part] != nameset[i][part]) { @@ -9032,7 +9327,7 @@ CSL.NameOutput.prototype._setEtAlParameter = function (type, v, j) { if (lst.length < count && !this.state.tmp.sort_key_flag) { if (this.etal_use_last) { if (type === "persons") { - this.etal_spec[v].persons[j] = 2 + this.etal_spec[v].persons[j] = 2; } else { this.etal_spec[v][type] = 2; } @@ -9074,9 +9369,9 @@ CSL.NameOutput.prototype.renderInstitutionNames = function () { for (var i = 0, ilen = this.variables.length; i < ilen; i += 1) { var v = this.variables[i]; for (var j = 0, jlen = this.institutions[v].length; j < jlen; j += 1) { - var institution, institution_short, institution_long, short_style, long_style; + var institution; var name = this.institutions[v][j]; - var j, ret, optLangTag, jlen, key, localesets; + var j, jlen, localesets; if (this.state.tmp.extension) { localesets = ["sort"]; } else if (name.isInstitution || name.literal) { @@ -9105,13 +9400,12 @@ CSL.NameOutput.prototype.renderInstitutionNames = function () { slot.secondary = false; slot.tertiary = false; } - var res; this.setRenderedName(name); var institution = this._renderInstitutionName(v, name, slot, j); this.institutions[v][j] = institution; } } -} +}; CSL.NameOutput.prototype._renderInstitutionName = function (v, name, slot, j) { var secondary, tertiary, long_style, short_style, institution, institution_short, institution_long; var res = this.getName(name, slot.primary, true); @@ -9194,7 +9488,7 @@ CSL.NameOutput.prototype._renderInstitutionName = function (v, name, slot, j) { this.state.tmp.name_node.children.push(blob); return blob; }; -CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, slot, style, v) { +CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, slot, style) { var primary = false, secondary = false, tertiary = false, primary_tok, secondary_tok, tertiary_tok; if (names[0]) { primary_tok = CSL.Util.cloneToken(style); @@ -9208,7 +9502,7 @@ CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, slot, sty } } if (!hasItalic) { - primary_tok.decorations.push(["@font-style", "italic"]) + primary_tok.decorations.push(["@font-style", "italic"]); } } } @@ -9258,7 +9552,7 @@ CSL.NameOutput.prototype._composeOneInstitutionPart = function (names, slot, sty institutionblob = primary; } return institutionblob; -} +}; CSL.NameOutput.prototype._renderOneInstitutionPart = function (blobs, style) { for (var i = 0, ilen = blobs.length; i < ilen; i += 1) { if (blobs[i]) { @@ -9294,7 +9588,7 @@ CSL.NameOutput.prototype._renderNames = function (v, values, pos, j) { var names = []; for (var i = 0, ilen = values.length; i < ilen; i += 1) { var name = values[i]; - var ret, optLangTag, jlen, key, localesets; + var ret, localesets; if (this.state.tmp.extension) { localesets = ["sort"]; } else if (name.isInstitution || name.literal) { @@ -9333,8 +9627,8 @@ CSL.NameOutput.prototype._renderNames = function (v, values, pos, j) { } ret = this.joinPersons(names, pos, j); } - return ret -} + return ret; +}; CSL.NameOutput.prototype._renderPersonalName = function (v, name, slot, pos, i, j) { var res = this.getName(name, slot.primary, true); var primary = this._renderOnePersonalName(res.name, pos, i, j); @@ -9497,13 +9791,11 @@ CSL.NameOutput.prototype._renderOnePersonalName = function (value, pos, i, j) { dropping_particle = false; } } - if (!this.state.tmp.term_predecessor) { - } var space = " "; if (this.state.inheritOpt(this.name, "initialize-with") && this.state.inheritOpt(this.name, "initialize-with").match(/[\u00a0\ufeff]/) && ["fr", "ru", "cs"].indexOf(this.state.opt["default-locale"][0].slice(0, 2)) > -1) { - space = "\u00a0" + space = "\u00a0"; } if (has_hyphenated_non_dropping_particle) { second = this._join([non_dropping_particle, family], ""); @@ -9616,9 +9908,8 @@ CSL.NameOutput.prototype._familyName = function (name) { CSL.NameOutput.prototype._givenName = function (name, pos, i) { var ret; var formIsShort = this.state.inheritOpt(this.name, "form", "name-form", "long") !== "long"; - var initializeIsTurnedOn = !(this.state.inheritOpt(this.name, "initialize") === false); + var initializeIsTurnedOn = this.state.inheritOpt(this.name, "initialize") !== false; var hasInitializeWith = "string" === typeof this.state.inheritOpt(this.name, "initialize-with") && !name.block_initialize; - var inBibliography = this.state.tmp.area.slice(0, 12) === "bibliography"; var defaultLevel; var useLevel; if (name["full-form-always"]) { @@ -9681,8 +9972,8 @@ CSL.NameOutput.prototype._nameSuffix = function (name) { } return false; }; -CSL.NameOutput.prototype._getLongStyle = function (name, v, i) { - var long_style, short_style; +CSL.NameOutput.prototype._getLongStyle = function (name) { + var long_style; if (name["short"].length) { if (this.institutionpart["long-with-short"]) { long_style = this.institutionpart["long-with-short"]; @@ -9707,7 +9998,6 @@ CSL.NameOutput.prototype._getShortStyle = function () { return short_style; }; CSL.NameOutput.prototype._parseName = function (name) { - var m, idx; if (!name["parse-names"] && "undefined" !== typeof name["parse-names"]) { return name; } @@ -9751,7 +10041,7 @@ CSL.NameOutput.prototype.getName = function (name, slotLocaleset, fallback, stop if (slotLocaleset !== 'locale-orig') { foundTag = false; if (name.multi) { - var langTags = this.state.opt[slotLocaleset] + var langTags = this.state.opt[slotLocaleset]; for (var i = 0, ilen = langTags.length; i < ilen; i += 1) { langTag = langTags[i]; if (name.multi._key[langTag]) { @@ -9824,14 +10114,14 @@ CSL.NameOutput.prototype.getName = function (name, slotLocaleset, fallback, stop usedOrig = !foundTag; } return {name:name,usedOrig:usedOrig}; -} +}; CSL.NameOutput.prototype.getNameParams = function (langTag) { var ret = {}; var langspec = CSL.localeResolve(this.Item.language, this.state.opt["default-locale"][0]); var try_locale = this.state.locale[langspec.best] ? langspec.best : this.state.opt["default-locale"][0]; - var name_as_sort_order = this.state.locale[try_locale].opts["name-as-sort-order"] - var name_as_reverse_order = this.state.locale[try_locale].opts["name-as-reverse-order"] - var name_never_short = this.state.locale[try_locale].opts["name-never-short"] + var name_as_sort_order = this.state.locale[try_locale].opts["name-as-sort-order"]; + var name_as_reverse_order = this.state.locale[try_locale].opts["name-as-reverse-order"]; + var name_never_short = this.state.locale[try_locale].opts["name-never-short"]; var field_lang_bare = langTag.split("-")[0]; if (name_as_sort_order && name_as_sort_order[field_lang_bare]) { ret["static-ordering"] = true; @@ -9848,7 +10138,7 @@ CSL.NameOutput.prototype.getNameParams = function (langTag) { ret["block-initialize"] = true; } return ret; -} +}; CSL.NameOutput.prototype.setRenderedName = function (name) { if (this.state.tmp.area === "bibliography") { var strname = ""; @@ -9859,7 +10149,7 @@ CSL.NameOutput.prototype.setRenderedName = function (name) { } this.state.tmp.rendered_name.push(strname); } -} +}; CSL.NameOutput.prototype.fixupInstitution = function (name, varname, listpos) { if (this.state.sys.getHumanForm && "legal_case" === this.Item.type && "authority" === varname) { name.literal = this.state.sys.getHumanForm(this.Item.jurisdiction, name.literal, true); @@ -9891,7 +10181,7 @@ CSL.NameOutput.prototype.fixupInstitution = function (name, varname, listpos) { name["short"] = []; } return name; -} +}; CSL.NameOutput.prototype.getStaticOrder = function (name, refresh) { var static_ordering_val = false; if (!refresh && name["static-ordering"]) { @@ -9910,7 +10200,7 @@ CSL.NameOutput.prototype.getStaticOrder = function (name, refresh) { } } return static_ordering_val; -} +}; CSL.NameOutput.prototype._splitInstitution = function (value, v, i) { var ret = {}; if (!value.literal && value.family) { @@ -9952,7 +10242,7 @@ CSL.NameOutput.prototype._splitInstitution = function (value, v, i) { ret["long"] = this._trimInstitution(splitInstitution, v, i); return ret; }; -CSL.NameOutput.prototype._trimInstitution = function (subunits, v, i) { +CSL.NameOutput.prototype._trimInstitution = function (subunits, v) { var use_first = false; var append_last = false; var s = subunits.slice(); @@ -10068,14 +10358,12 @@ CSL.PublisherOutput.prototype.composeElements = function () { CSL.PublisherOutput.prototype.composePublishers = function () { var blobs; for (var i = 0, ilen = this["publisher-list"].length; i < ilen; i += 1) { - var ordered_list = []; blobs = [this[this.varlist[0] + "-list"][i], this[this.varlist[1] + "-list"][i]]; this["publisher-list"][i] = this._join(blobs, this.group_tok.strings.delimiter); } }; CSL.PublisherOutput.prototype.joinPublishers = function () { var blobs = this["publisher-list"]; - var delim = this.name_delimiter; var publishers = this._join(blobs, this.group_tok.strings["subgroup-delimiter"], this.and_blob.single, this.and_blob.multiple, this.group_tok); this.state.output.append(publishers, "literal"); }; @@ -10153,7 +10441,7 @@ CSL.castLabel = function (state, node, term, plural, mode) { }; CSL.Node.name = { build: function (state, target) { - var func, pos, len, attrname; + var func; if ([CSL.SINGLETON, CSL.START].indexOf(this.tokentype) > -1) { var oldTmpRoot; if ("undefined" === typeof state.tmp.root) { @@ -10171,7 +10459,7 @@ CSL.Node.name = { state.opt.update_mode = CSL.POSITION; } state.tmp.root = oldTmpRoot; - func = function (state, Item) { + func = function (state) { state.tmp.etal_term = "et-al"; state.tmp.name_delimiter = state.inheritOpt(this, "delimiter", "name-delimiter", ", "); state.tmp["delimiter-precedes-et-al"] = state.inheritOpt(this, "delimiter-precedes-et-al"); @@ -10260,23 +10548,28 @@ CSL.Node.name = { } }; CSL.Node["name-part"] = { - build: function (state, target) { + build: function (state) { state.build[this.strings.name] = this; } }; CSL.Node.names = { build: function (state, target) { - var func, len, pos, attrname; - var debug = false; + var func; if (this.tokentype === CSL.START || this.tokentype === CSL.SINGLETON) { CSL.Util.substituteStart.call(this, state, target); state.build.substitute_level.push(1); } if (this.tokentype === CSL.SINGLETON) { - state.build.names_variables.push(this.variables); - func = function (state, Item, item) { - var labelVariable = state.nameOutput.labelVariable; - state.nameOutput.reinit(this, labelVariable); + state.build.names_variables[state.build.names_variables.length-1].concat(this.variables); + for (var i in this.variables) { + var variable = this.variables[i]; + var name_labels = state.build.name_label[state.build.name_label.length-1]; + if (Object.keys(name_labels).length) { + name_labels[variable] = name_labels[Object.keys(name_labels)[0]]; + } + } + func = function (state) { + state.nameOutput.reinit(this, this.variables_real[0]); }; this.execs.push(func); } @@ -10284,12 +10577,9 @@ CSL.Node.names = { state.build.names_flag = true; state.build.name_flag = false; state.build.names_level += 1; - if (state.build.names_level === 1) { - state.build.names_variables = []; - state.build.name_label = {}; - } state.build.names_variables.push(this.variables); - func = function (state, Item, item) { + state.build.name_label.push({}); + func = function (state) { state.tmp.can_substitute.push(true); state.parallel.StartVariable("names",this.variables[0]); state.nameOutput.init(this); @@ -10304,13 +10594,11 @@ CSL.Node.names = { state.build[key] = undefined; } } - this.label = state.build.name_label; - if (state.build.names_level === 1) { - state.build.name_label = {}; - } + this.label = state.build.name_label[state.build.name_label.length-1]; state.build.names_level += -1; state.build.names_variables.pop(); - func = function (state, Item, item) { + state.build.name_label.pop(); + func = function (state) { if (state.tmp.etal_node) { this.etal_style = state.tmp.etal_node; } else { @@ -10377,7 +10665,7 @@ CSL.Node.names = { state.tmp["et-al-use-last"] = undefined; }; this.execs.push(func); - func = function (state, Item) { + func = function (state) { if (!state.tmp.can_substitute.pop()) { state.tmp.can_substitute.replace(false, CSL.LITERAL); } @@ -10414,14 +10702,13 @@ CSL.Node.number = { this.splice_prefix = state[state.build.area].opt.layout_delimiter; } func = function (state, Item, item) { - var i, ilen, newlst, lst; if (this.variables.length === 0) { return; } if ("undefined" === typeof item) { var item = {}; } - var varname, num, number, m, j, jlen; + var varname; varname = this.variables[0]; if (varname === "locator" && state.tmp.just_looking) { return; @@ -10432,16 +10719,14 @@ CSL.Node.number = { } else { state.parallel.AppendToVariable(Item[this.variables[0]]); } - var rex = new RegExp("(?:&|, | and |" + state.getTerm("page-range-delimiter") + ")"); if (varname === 'collection-number' && Item.type === 'legal_case') { state.tmp.renders_collection_number = true; } - var value = Item[this.variables[0]]; var node = this; if (state.tmp.group_context.tip.force_suppress) { return false; } - if (varname === "locator") { + if (["locator", "locator-extra"].indexOf(varname) > -1) { state.processNumber(node, item, varname, Item.type); } else { if (!state.tmp.group_context.tip.condition && Item[varname]) { @@ -10492,18 +10777,18 @@ CSL.Node.sort = { state.tmp.lang_sort_hold = state.opt.lang; state.opt.lang = langForItem; } - } + }; this.execs.push(func); } if (this.tokentype === CSL.END) { state.build.area = state.build.root; state.build.extension = ""; - var func = function (state, Item) { + var func = function (state) { if (state.opt.has_layout_locale) { state.opt.lang = state.tmp.lang_sort_hold; delete state.tmp.lang_sort_hold; } - } + }; this.execs.push(func); } target.push(this); @@ -10513,11 +10798,12 @@ CSL.Node.substitute = { build: function (state, target) { var func; if (this.tokentype === CSL.START) { - func = function (state, Item) { + func = function (state) { state.tmp.can_block_substitute = true; - if (state.tmp.value.length) { + if (state.tmp.value.length && !state.tmp.common_term_match_fail) { state.tmp.can_substitute.replace(false, CSL.LITERAL); } + state.tmp.common_term_match_fail = false; }; this.execs.push(func); } @@ -10526,7 +10812,7 @@ CSL.Node.substitute = { }; CSL.Node.text = { build: function (state, target) { - var variable, func, form, plural, id, num, number, formatter, firstoutput, specialdelimiter, label, myname, names, name, year, suffix, term, dp, len, pos, n, m, value, flag; + var func, form, plural, id, num, number, formatter, firstoutput, specialdelimiter, label, suffix, term; if (this.postponed_macro) { var group_start = CSL.Util.cloneToken(this); group_start.name = "group"; @@ -10576,20 +10862,7 @@ CSL.Node.text = { id = "" + Item.id; if (!state.tmp.just_looking) { if (item && item["author-only"]) { - state.tmp.element_trace.replace("do-not-suppress-me"); - var reference_term = state.getTerm("reference", "long", "singular"); - if ("undefined" === typeof reference_term) { - reference_term = "reference"; - } - term = CSL.Output.Formatters["capitalize-first"](state, reference_term); - state.output.append(term + " "); - state.tmp.last_element_trace = true; - } - if (item && item["suppress-author"]) { - if (state.tmp.last_element_trace) { - state.tmp.element_trace.replace("suppress-me"); - } - state.tmp.last_element_trace = false; + state.tmp.element_trace.replace("suppress-me"); } num = state.registry.registry[id].seq; if (state.opt.citation_number_slug) { @@ -10597,8 +10870,6 @@ CSL.Node.text = { } else { number = new CSL.NumericBlob(false, num, this, Item.id); if (state.tmp.in_cite_predecessor) { - if (!state.tmp.just_looking) { - } number.suppress_splice_prefix = true; } state.output.append(number, "literal"); @@ -10641,6 +10912,9 @@ CSL.Node.text = { }; this.execs.push(func); } else if (this.variables_real[0] === "citation-label") { + if (state.build.root === "bibliography") { + state.opt.bib_mode = CSL.TRIGRAPH; + } state.opt.has_year_suffix = true; func = function (state, Item) { label = Item["citation-label"]; @@ -10661,7 +10935,7 @@ CSL.Node.text = { } } else { if (this.strings.term) { - func = function (state, Item, item) { + func = function (state, Item) { var gender = state.opt.gender[Item.type]; var term = this.strings.term; term = state.getTerm(term, form, plural, gender, CSL.TOLERANT, this.default_locale); @@ -10692,7 +10966,7 @@ CSL.Node.text = { state.build.form = false; state.build.plural = false; } else if (this.variables_real.length) { - func = function (state, Item, item) { + func = function (state, Item) { if (this.variables_real[0] !== "locator") { state.tmp.have_collapsed = false; } @@ -10744,7 +11018,7 @@ CSL.Node.text = { func = function(state, Item) { state.processNumber(this, Item, this.variables[0], Item.type); CSL.Util.outputNumericField(state, this.variables[0], Item.id); - } + }; } else if (["URL", "DOI"].indexOf(this.variables_real[0]) > -1) { func = function (state, Item) { var value; @@ -10753,10 +11027,10 @@ CSL.Node.text = { if (value) { if (state.opt.development_extensions.wrap_url_and_doi) { if (!this.decorations.length || this.decorations[0][0] !== "@" + this.variables[0]) { + var clonetoken = CSL.Util.cloneToken(this); + var groupblob = new CSL.Blob(null, null, "url-wrapper"); + groupblob.decorations.push(["@DOI", "true"]); if (this.variables_real[0] === "DOI") { - var clonetoken = CSL.Util.cloneToken(this); - var groupblob = new CSL.Blob(null, null, "url-wrapper"); - groupblob.decorations.push(["@DOI", "true"]); var prefix; if (this.strings.prefix && this.strings.prefix.match(/^.*https:\/\/doi\.org\/$/)) { value = value.replace(/^https?:\/\/doi\.org\//, ""); @@ -10773,8 +11047,9 @@ CSL.Node.text = { groupblob.push(valueblob); state.output.append(groupblob, clonetoken, false, false, true); } else { - this.decorations = [["@" + this.variables[0], "true"]].concat(this.decorations); - state.output.append(value, this, false, false, true); + var valueblob = new CSL.Blob(value); + groupblob.push(valueblob); + state.output.append(groupblob, clonetoken, false, false, true); } } else { state.output.append(value, this, false, false, true); @@ -10807,7 +11082,7 @@ CSL.Node.text = { state.output.append(value, this); state.tmp.group_context.tip.variable_success = true; } - } + }; } else { func = function (state, Item) { var value; @@ -10823,12 +11098,12 @@ CSL.Node.text = { } } this.execs.push(func); - func = function (state, Item) { + func = function (state) { state.parallel.CloseVariable("text"); }; this.execs.push(func); } else if (this.strings.value) { - func = function (state, Item) { + func = function (state) { state.tmp.group_context.tip.term_intended = true; CSL.UPDATE_GROUP_CONTEXT_CONDITION(state, this.strings.value, true); state.output.append(this.strings.value, this); @@ -10841,22 +11116,53 @@ CSL.Node.text = { } } }; +CSL.Node.intext = { + build: function (state, target) { + if (this.tokentype === CSL.START) { + state.build.area = "intext"; + state.build.root = "intext"; + state.build.extension = ""; + var func = function(state, Item) { + state.tmp.area = "intext"; + state.tmp.root = "intext"; + state.tmp.extension = ""; + } + this.execs.push(func); + } + if (this.tokentype === CSL.END) { + state.opt.grouped_sort = state.opt.xclass === "in-text" + && (state.citation.opt.collapse + && state.citation.opt.collapse.length) + || (state.citation.opt.cite_group_delimiter + && state.citation.opt.cite_group_delimiter.length) + && state.opt.update_mode !== CSL.POSITION + && state.opt.update_mode !== CSL.NUMERIC; + if (state.opt.grouped_sort + && state.citation_sort.opt.sort_directions.length) { + state.intext_sort.opt.sort_directions = state.citation_sort.opt.sort_directions; + } + state.intext.srt = state.citation.srt; + } + target.push(this); + } +}; CSL.Attributes = {}; CSL.Attributes["@genre"] = function (state, arg) { + this.tests ? {} : this.tests = []; arg = arg.replace("-", " "); - var func = function (Item, item) { - var ret; + var func = function (Item) { if (arg === Item.genre) { return true; } return false; - } + }; this.tests.push(func); -} +}; CSL.Attributes["@disambiguate"] = function (state, arg) { + this.tests ? {} : this.tests = []; if (arg === "true") { state.opt.has_disambiguate = true; - var func = function (Item, item) { + var func = function (Item) { if (state.tmp.area === "bibliography") { if (state.tmp.disambiguate_count < state.registry.registry[Item.id].disambig.disambiguate) { state.tmp.disambiguate_count += 1; @@ -10874,7 +11180,7 @@ CSL.Attributes["@disambiguate"] = function (state, arg) { }; this.tests.push(func); } else if (arg === "check-ambiguity-and-backreference") { - var func = function (Item, item) { + var func = function (Item) { if (state.registry.registry[Item.id].disambig.disambiguate && state.registry.registry[Item.id]["citation-count"] > 1) { return true; } @@ -10883,7 +11189,8 @@ CSL.Attributes["@disambiguate"] = function (state, arg) { this.tests.push(func); } }; -CSL.Attributes["@is-numeric"] = function (state, arg, joiner) { +CSL.Attributes["@is-numeric"] = function (state, arg) { + this.tests ? {} : this.tests = []; var variables = arg.split(/\s+/); var maketest = function(variable) { return function (Item, item) { @@ -10909,28 +11216,30 @@ CSL.Attributes["@is-numeric"] = function (state, arg, joiner) { } } return false; - } - } + }; + }; for (var i=0; i= CSL.POSITION_SUBSEQUENT && item["near-note"]) { + return true; + } + return false; + }; + var testSubsequentNotNear = function (Item, item) { + if (item && item.position == CSL.POSITION_SUBSEQUENT && !item["near-note"]) { + return true; + } + return false; + }; var maketest = function(tryposition) { return function (Item, item) { if (state.tmp.area === "bibliography") { @@ -10972,8 +11294,8 @@ CSL.Attributes["@position"] = function (state, arg) { return true; } return false; - } - } + }; + }; for (var i=0,ilen=trypositions.length;i= CSL.POSITION_SUBSEQUENT && item["near-note"]) { - return true; - } - return false; - }); + this.tests.push(testSubsequentNear); } else if ("far-note" === tryposition) { - this.tests.push(function (Item, item) { - if (item && item.position == CSL.POSITION_SUBSEQUENT && !item["near-note"]) { - return true; - } - return false; - }); + this.tests.push(testSubsequentNotNear); } else { this.tests.push(maketest(tryposition)); } } }; CSL.Attributes["@type"] = function (state, arg) { + this.tests ? {} : this.tests = []; var types = arg.split(/\s+/); var maketest = function (mytype) { - return function(Item,item) { + return function(Item) { var ret = (Item.type === mytype); if (ret) { return true; } else { return false; } - } - } + }; + }; var tests = []; for (var i=0,ilen=types.length;i -1 && "string" === typeof Item[variable] && "names" === this.name) { - var creatorParents = []; var isValid = true; var rawNames = Item[variable].split(/\s*;\s*/); var rawMultiNames = {}; @@ -11080,7 +11391,7 @@ CSL.Attributes["@variable"] = function (state, arg) { for (var langTag in rawMultiNames) { var creatorChild = { literal:rawMultiNames[langTag][j] - } + }; creatorParent.multi._key[langTag] = creatorChild; } rawNames[j] = creatorParent; @@ -11142,8 +11453,6 @@ CSL.Attributes["@variable"] = function (state, arg) { } break; } else if ("object" === typeof Item[variable]) { - if (Item[variable].length) { - } break; } else if ("string" === typeof Item[variable] && Item[variable]) { output = true; @@ -11199,18 +11508,19 @@ CSL.Attributes["@variable"] = function (state, arg) { } } return false; - } - } + }; + }; for (var i=0,ilen=this.variables.length;i -1) { + var area = state.tmp.area.slice(0, arg.length); + if (area === arg) { + return true; + } + return false; + } else if ("alternative" === arg) { + return !!state.tmp.abort_alternative; + } }; this.tests.push(func); }; CSL.Attributes["@has-year-only"] = function (state, arg) { + this.tests ? {} : this.tests = []; var trydates = arg.split(/\s+/); var maketest = function (trydate) { - return function(Item,item){ + return function(Item) { var date = Item[trydate]; if (!date || date.month || date.season) { return false; } else { return true; } - } - } + }; + }; for (var i=0,ilen=trydates.length;i -1) { + state.tmp.condition_lang_counter_arr.push(state.tmp.condition_counter); + state.tmp.condition_lang_val_arr.push(state.opt.lang); + state.opt.lang = locale_list[0].best; res = true; } return res; - } - } + }; + }; this.tests.push(maketest(locale_list,locale_default,locale_bares)); } }; CSL.Attributes["@authority-residue"] = function (state, arg) { + this.tests ? {} : this.tests = []; var maketest = function () { var succeed = (arg === "true") ? true : false; - return function(Item, item) { - if (!Item.authority || !Item.authority[0] || !Item.authority[0].family) return !succeed; + 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) { @@ -11467,12 +11806,23 @@ CSL.Attributes["@authority-residue"] = function (state, arg) { } else { return !succeed; } - } - } + }; + }; this.tests.push(maketest()); -} +}; +CSL.Attributes["@alternative-node-internal"] = function (state) { + this.tests ? {} : this.tests = []; + var maketest = function () { + return function() { + return !state.tmp.abort_alternative; + }; + }; + var me = this; + this.tests.push(maketest(me)); +}; CSL.Attributes["@locale-internal"] = function (state, arg) { - var func, ret, len, pos, variable, myitem, langspec, lang, lst, i, ilen, fallback; + this.tests ? {} : this.tests = []; + var langspec, lang, lst, i, ilen; lst = arg.split(/\s+/); this.locale_bares = []; for (i = 0, ilen = lst.length; i < ilen; i += 1) { @@ -11488,8 +11838,8 @@ CSL.Attributes["@locale-internal"] = function (state, arg) { this.locale = lst[0].best; this.locale_list = lst.slice(); var maketest = function (me) { - return function (Item, item) { - var key, res; + return function (Item) { + var ret, res; ret = []; res = false; var langspec = false; @@ -11520,11 +11870,11 @@ CSL.Attributes["@locale-internal"] = function (state, arg) { } } return res; - } - } + }; + }; var me = this; this.tests.push(maketest(me)); -} +}; CSL.Attributes["@is-parallel"] = function (state, arg) { var values = arg.split(" "); for (var i = 0, ilen = values.length; i < ilen; i += 1) { @@ -11541,13 +11891,13 @@ CSL.Attributes["@jurisdiction-depth"] = function (state, arg) { }; CSL.Attributes["@require"] = function (state, arg) { this.strings.require = arg; -} +}; CSL.Attributes["@reject"] = function (state, arg) { this.strings.reject = arg; -} +}; CSL.Attributes["@gender"] = function (state, arg) { this.gender = arg; -} +}; CSL.Attributes["@cslid"] = function (state, arg) { this.cslid = parseInt(arg, 10); }; @@ -11600,15 +11950,14 @@ CSL.Attributes["@term"] = function (state, arg) { this.strings.term = arg; } }; -CSL.Attributes["@xmlns"] = function (state, arg) {}; +CSL.Attributes["@xmlns"] = function () {}; CSL.Attributes["@lang"] = function (state, arg) { if (arg) { state.build.lang = arg; } }; -CSL.Attributes["@lingo"] = function (state, arg) { -}; -CSL.Attributes["@macro-has-date"] = function (state, arg) { +CSL.Attributes["@lingo"] = function () {}; +CSL.Attributes["@macro-has-date"] = function () { this["macro-has-date"] = true; }; CSL.Attributes["@suffix"] = function (state, arg) { @@ -11654,7 +12003,7 @@ CSL.Attributes["@plural"] = function (state, arg) { this.strings.plural = false; } }; -CSL.Attributes["@has-publisher-and-publisher-place"] = function (state, arg) { +CSL.Attributes["@has-publisher-and-publisher-place"] = function () { this.strings["has-publisher-and-publisher-place"] = true; }; CSL.Attributes["@publisher-delimiter-precedes-last"] = function (state, arg) { @@ -11666,8 +12015,7 @@ CSL.Attributes["@publisher-delimiter"] = function (state, arg) { CSL.Attributes["@publisher-and"] = function (state, arg) { this.strings["publisher-and"] = arg; }; -CSL.Attributes["@newdate"] = function (state, 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; @@ -11761,6 +12109,17 @@ CSL.Attributes["@name-as-sort-order"] = function (state, arg) { CSL.Attributes["@sort-separator"] = function (state, arg) { state.setOpt(this, "sort-separator", arg); }; +CSL.Attributes["@require-match"] = function (state, arg) { + if (arg === "true") { + this.requireMatch = true; + } +}; +CSL.Attributes["@exclude-types"] = function (state, arg) { + state.bibliography.opt.exclude_types = arg.split(/\s+/); +}; +CSL.Attributes["@exclude-with-fields"] = function (state, arg) { + state.bibliography.opt.exclude_with_fields = arg.split(/\s+/); +}; CSL.Attributes["@year-suffix-delimiter"] = function (state, arg) { state[this.name].opt["year-suffix-delimiter"] = arg; }; @@ -11795,7 +12154,11 @@ CSL.Attributes["@second-field-align"] = function (state, arg) { }; CSL.Attributes["@hanging-indent"] = function (state, arg) { if (arg === "true") { - state[this.name].opt.hangingindent = 2; + if (state.opt.development_extensions.hanging_indent_legacy_number) { + state[this.name].opt.hangingindent = 2; + } else { + state[this.name].opt.hangingindent = true; + } } }; CSL.Attributes["@line-spacing"] = function (state, arg) { @@ -11818,8 +12181,6 @@ CSL.Attributes["@text-case"] = function (state, arg) { } else { this.strings["text-case"] = arg; if (arg === "title") { - var m = false; - var default_locale = state.opt["default-locale"][0].slice(0, 2); if (Item.jurisdiction) { this.strings["text-case"] = "passthrough"; } @@ -11864,7 +12225,6 @@ CSL.Attributes["@default-locale"] = function (state, arg) { } }; CSL.Attributes["@default-locale-sort"] = function (state, arg) { - var lst, len, pos, m, ret; state.opt["default-locale-sort"] = arg; }; CSL.Attributes["@demote-non-dropping-particle"] = function (state, arg) { @@ -11984,7 +12344,7 @@ CSL.Parallel.prototype.StartCitation = function (sortedItems, out) { } }; CSL.Parallel.prototype.StartCite = function (Item, item, prevItemID) { - var position, len, pos, x, curr, master, last_id, prev_locator, curr_locator, is_master, parallel; + var position, len, pos, curr, master, last_id, prev_locator, curr_locator; if (this.use_parallels) { if (this.sets.value().length && this.sets.value()[0].itemId == Item.id) { this.ComposeSet(); @@ -12163,7 +12523,7 @@ CSL.Parallel.prototype.AppendBlobPointer = function (blob) { } } }; -CSL.Parallel.prototype.AppendToVariable = function (str, varname) { +CSL.Parallel.prototype.AppendToVariable = function (str) { if (this.use_parallels) { if (this.ignoreVars.indexOf(this.variable) > -1) { return; @@ -12230,7 +12590,7 @@ CSL.Parallel.prototype.CloseVariable = function () { } }; CSL.Parallel.prototype.CloseCite = function () { - var x, pos, len, has_issued, use_journal_info, volume_pos, container_title_pos, section_pos; + var x, pos, len, use_journal_info, volume_pos, container_title_pos, section_pos; if (this.use_parallels && (this.force_collapse || this.try_cite)) { use_journal_info = false; if (!this.cite.front_collapse["container-title"]) { @@ -12297,8 +12657,8 @@ CSL.Parallel.prototype.CloseCite = function () { this.sets.value().push(this.cite); } }; -CSL.Parallel.prototype.ComposeSet = function (next_output_in_progress) { - var cite, pos, master, len; +CSL.Parallel.prototype.ComposeSet = function () { + var cite, pos, len; if (this.use_parallels && (this.force_collapse || this.try_cite)) { var lengthCheck = this.sets.value().length; if (this.sets.value().length === 1) { @@ -12433,7 +12793,7 @@ CSL.Parallel.prototype.purgeGroupsIfParallel = function (original_condition) { } this.parallel_conditional_blobs_list.pop(); } -} +}; CSL.Util = {}; CSL.Util.Match = function () { this.any = function (token, state, tests) { @@ -12483,10 +12843,8 @@ CSL.Util.Match = function () { }; }; CSL.Transform = function (state) { - var debug = false, abbreviations, token, fieldname, abbrev_family, opt; this.abbrevs = {}; this.abbrevs["default"] = new state.sys.AbbreviationSegments(); - this.getTextSubField = getTextSubField; function getCountryOrJurisdiction(variable, normalizedKey, quashCountry) { var value = ""; if (state.sys.getHumanForm) { @@ -12504,7 +12862,7 @@ CSL.Transform = function (state) { } return value; } - function abbreviate(state, tok, Item, altvar, basevalue, family_var, use_field, form) { + function abbreviate(state, tok, Item, altvar, basevalue, family_var, use_field) { var value = ""; var myabbrev_family = CSL.FIELD_CATEGORY_REMAP[family_var]; var preferredJurisdiction; @@ -12556,7 +12914,7 @@ CSL.Transform = function (state) { return value; } function getFieldLocale(Item,field) { - var ret = state.opt["default-locale"][0].slice(0, 2) + var ret = state.opt["default-locale"][0].slice(0, 2); var localeRex; if (state.opt.development_extensions.strict_text_case_locales) { localeRex = new RegExp("^([a-zA-Z]{2})(?:$|-.*| .*)"); @@ -12579,9 +12937,9 @@ CSL.Transform = function (state) { ret = ret.toLowerCase(); } return ret; - }; + } function getTextSubField (Item, field, locale_type, use_default, stopOrig) { - var m, lst, opt, o, oo, pos, key, ret, len, myret, opts; + var opt, o, ret, opts; var usedOrig = stopOrig; var usingOrig = false; if (!Item[field]) { @@ -12594,7 +12952,6 @@ CSL.Transform = function (state) { ret = {name:"", usedOrig:stopOrig,locale:getFieldLocale(Item,field)}; opts = state.opt[locale_type]; var hasVal = false; - var jurisdictionName = false; if (locale_type === 'locale-orig') { if (stopOrig) { ret = {name:"", usedOrig:stopOrig}; @@ -12642,8 +12999,8 @@ CSL.Transform = function (state) { } return ret; } + this.getTextSubField = getTextSubField; function loadAbbreviation(jurisdiction, category, orig, itemType) { - var pos, len; if (!jurisdiction) { jurisdiction = "default"; } @@ -12686,7 +13043,21 @@ CSL.Transform = function (state) { } return false; } - function getOutputFunction(variables, family_var, abbreviation_fallback, alternative_varname, transform_fallback) { + function quashCheck(value) { + var m = value.match(/^!([-,_a-z]+)>>>/); + if (m) { + var fields = m[1].split(","); + value = value.slice(m[0].length); + for (var i = 0, ilen = fields.length; i < ilen; i += 1) { + if (state.tmp.done_vars.indexOf(fields[i]) === -1) { + state.tmp.done_vars.push(fields[i]); + } + } + } + return value; + } + this.quashCheck = quashCheck; + function getOutputFunction(variables, family_var, abbreviation_fallback, alternative_varname) { var localesets; var langPrefs = CSL.LangPrefsMap[variables[0]]; if (!langPrefs) { @@ -12694,16 +13065,21 @@ CSL.Transform = function (state) { } else { localesets = state.opt['cite-lang-prefs'][langPrefs]; } - return function (state, Item, item, usedOrig) { - var primary, primary_locale, secondary, secondary_locale, tertiary, tertiary_locale, primary_tok, group_tok, key; + return function (state, Item, item) { + var primary, primary_locale, secondary, secondary_locale, tertiary, tertiary_locale, primary_tok; if (!variables[0] || (!Item[variables[0]] && !Item[alternative_varname])) { return null; } + if (!state.tmp.just_looking && item && item["suppress-author"]) { + if (!state.tmp.probably_rendered_something && state.tmp.can_substitute.length() > 1) { + return null; + } + } var slot = {primary:false, secondary:false, tertiary:false}; if (state.tmp.area.slice(-5) === "_sort") { slot.primary = 'locale-sort'; } else { - if (localesets) { + if (localesets && !state.tmp.multi_layout) { var slotnames = ["primary", "secondary", "tertiary"]; for (var i = 0, ilen = slotnames.length; i < ilen; i += 1) { if (localesets.length - 1 < i) { @@ -12725,6 +13101,10 @@ CSL.Transform = function (state) { slot.secondary = false; slot.tertiary = false; } + if (state.tmp.multi_layout) { + slot.secondary = false; + slot.tertiary = false; + } if (state.tmp["publisher-list"]) { if (variables[0] === "publisher") { state.tmp["publisher-token"] = this; @@ -12782,7 +13162,7 @@ CSL.Transform = function (state) { } } if (!hasItalic) { - primary_tok.decorations.push(["@font-style", "italic"]) + primary_tok.decorations.push(["@font-style", "italic"]); } } if (primary_locale !== "en" && primary_tok.strings["text-case"] === "title") { @@ -12795,6 +13175,7 @@ CSL.Transform = function (state) { state.output.openLevel("empty"); primary_tok.strings.suffix = primary_tok.strings.suffix.replace(/[ .,]+$/,""); state.output.append(primary, primary_tok); + state.tmp.probably_rendered_something = true; if (secondary) { secondary_tok.strings.prefix = state.opt.citeAffixes[langPrefs][slot.secondary].prefix; secondary_tok.strings.suffix = state.opt.citeAffixes[langPrefs][slot.secondary].suffix; @@ -12803,7 +13184,7 @@ CSL.Transform = function (state) { } for (var i = secondary_tok.decorations.length - 1; i > -1; i += -1) { if (['@quotes/true', '@font-style/italic', '@font-style/oblique', '@font-weight/bold'].indexOf(secondary_tok.decorations[i].join('/')) > -1) { - secondary_tok.decorations = secondary_tok.decorations.slice(0, i).concat(secondary_tok.decorations.slice(i + 1)) + secondary_tok.decorations = secondary_tok.decorations.slice(0, i).concat(secondary_tok.decorations.slice(i + 1)); } } if (secondary_locale !== "en" && secondary_tok.strings["text-case"] === "title") { @@ -12830,7 +13211,7 @@ CSL.Transform = function (state) { } for (var i = tertiary_tok.decorations.length - 1; i > -1; i += -1) { if (['@quotes/true', '@font-style/italic', '@font-style/oblique', '@font-weight/bold'].indexOf(tertiary_tok.decorations[i].join('/')) > -1) { - tertiary_tok.decorations = tertiary_tok.decorations.slice(0, i).concat(tertiary_tok.decorations.slice(i + 1)) + tertiary_tok.decorations = tertiary_tok.decorations.slice(0, i).concat(tertiary_tok.decorations.slice(i + 1)); } } if (tertiary_locale !== "en" && tertiary_tok.strings["text-case"] === "title") { @@ -12852,27 +13233,14 @@ CSL.Transform = function (state) { state.output.closeLevel(); } else { state.output.append(primary, primary_tok); + state.tmp.probably_rendered_something = true; } return null; }; } this.getOutputFunction = getOutputFunction; - function quashCheck(value) { - var m = value.match(/^!([-,_a-z]+)>>>/); - if (m) { - var fields = m[1].split(","); - value = value.slice(m[0].length); - for (var i = 0, ilen = fields.length; i < ilen; i += 1) { - if (state.tmp.done_vars.indexOf(fields[i]) === -1) { - state.tmp.done_vars.push(fields[i]); - } - } - } - return value; - } - this.quashCheck = quashCheck; }; -CSL.Token = function (name, tokentype) { +CSL.Token = function (name, tokentype, conditional) { this.name = name; this.strings = {}; this.strings.delimiter = undefined; @@ -12882,12 +13250,6 @@ CSL.Token = function (name, tokentype) { this.variables = []; this.execs = []; this.tokentype = tokentype; - this.evaluator = false; - this.tests = []; - this.rawtests = []; - this.succeed = false; - this.fail = false; - this.next = false; }; CSL.Util.cloneToken = function (token) { var newtok, key, pos, len; @@ -12911,8 +13273,9 @@ CSL.Util.cloneToken = function (token) { } if (token.execs) { newtok.execs = token.execs.slice(); - newtok.tests = token.tests.slice(); - newtok.rawtests = token.tests.slice(); + if (token.tests) { + newtok.tests = token.tests.slice(); + } } return newtok; }; @@ -13048,7 +13411,7 @@ CSL.NumericBlob.prototype.checkLast = function (last) { return false; }; CSL.Util.fixDateNode = function (parent, pos, node) { - var form, variable, datexml, subnode, partname, attr, val, prefix, suffix, children, key, subchildren, kkey, display, cslid; + var form, variable, datexml, subnode, partname, attr, val, prefix, suffix, children, subchildren, display, cslid; var lingo = this.cslXml.getAttributeValue(node, "lingo"); var default_locale = this.cslXml.getAttributeValue(node, "default-locale"); this.build.date_key = true; @@ -13135,7 +13498,7 @@ CSL.dateMacroAsSortKey = function (state, Item) { CSL.dateAsSortKey.call(this, state, Item, true); }; CSL.dateAsSortKey = function (state, Item, isMacro) { - var dp, elem, value, e, yr, prefix, i, ilen, num; + var dp, elem, value, e, yr, prefix, i, ilen; var variable = this.variables[0]; var macroFlag = "empty"; if (isMacro && state.tmp.extension) { @@ -13188,7 +13551,7 @@ CSL.dateAsSortKey = function (state, Item, isMacro) { } }; CSL.Engine.prototype.dateParseArray = function (date_obj) { - var ret, field, dpos, ppos, dp, exts, llen, pos, len, pppos, lllen; + var ret, field, dp, exts; ret = {}; for (field in date_obj) { if (field === "date-parts") { @@ -13238,7 +13601,7 @@ CSL.Util.Names.unInitialize = function (state, name) { return ret; }; CSL.Util.Names.initializeWith = function (state, name, terminator, normalizeOnly) { - var i, ilen, j, jlen, n, m, mm, str, lst, ret; + var i, ilen, mm, lst, ret; if (!name) { return ""; } @@ -13256,8 +13619,19 @@ CSL.Util.Names.initializeWith = function (state, name, terminator, normalizeOnly } namelist = namelist.replace(/\s*\-\s*/g, "-").replace(/\s+/g, " "); namelist = namelist.replace(/-([a-z])/g, "\u2013$1"); + for (var i=namelist.length-2; i>-1; i += -1) { + if (namelist.slice(i, i+1) === "." && namelist.slice(i+1, i+2) !== " ") { + namelist = namelist.slice(0, i) + ". " + namelist.slice(i+1); + } + } mm = namelist.match(/[\-\s]+/g); lst = namelist.split(/[\-\s]+/); + if (mm === null) { + var mmm = lst[0].match(/[^\.]+$/); + if (mmm && mmm[0].length === 1 && mmm[0] !== mmm[0].toLowerCase()) { + lst[0] += "."; + } + } if (lst.length === 0) { namelist = mm; } else { @@ -13268,20 +13642,6 @@ CSL.Util.Names.initializeWith = function (state, name, terminator, normalizeOnly } } lst = namelist; - for (i = lst.length -1; i > -1; i += -1) { - if (lst[i] && lst[i].slice(0, -1).indexOf(".") > -1) { - var lstend = lst.slice(i + 1); - var lstmid = lst[i].slice(0, -1).split("."); - lst = lst.slice(0, i); - for (j = 0, jlen = lstmid.length; j < jlen; j += 1) { - lst.push(lstmid[j] + "."); - if (j < lstmid.length - 1) { - lst.push(" "); - } - } - lst = lst.concat(lstend); - } - } if (normalizeOnly) { ret = CSL.Util.Names.doNormalize(state, lst, terminator); } else { @@ -13290,7 +13650,7 @@ CSL.Util.Names.initializeWith = function (state, name, terminator, normalizeOnly ret = ret.replace(/\u2013([a-z])/g, "-$1"); return ret; }; -CSL.Util.Names.doNormalize = function (state, namelist, terminator, mode) { +CSL.Util.Names.doNormalize = function (state, namelist, terminator) { var i, ilen; terminator = terminator ? terminator : ""; var isAbbrev = []; @@ -13304,20 +13664,11 @@ CSL.Util.Names.doNormalize = function (state, namelist, terminator, mode) { isAbbrev.push(false); } } - var ret = []; for (i = 0, ilen = namelist.length; i < ilen; i += 2) { if (isAbbrev[i]) { if (i < namelist.length - 2) { namelist[i + 1] = ""; - var onlySpace = terminator.match(/^[\u0009\u000a\u000b\u000c\u000d\u0020\u00a0]+$/) - if ( - onlySpace - || ( - (!terminator || (terminator.slice(-1) && !terminator.slice(-1).match(/[\u0009\u000a\u000b\u000c\u000d\u0020\u00a0]/))) - && namelist[i].length && namelist[i].match(CSL.ALL_ROMANESQUE_REGEXP) - && (namelist[i].length > 1 || namelist[i + 2].length > 1) - ) - ) { + if (!isAbbrev[i+2]) { namelist[i + 1] = " "; } if (namelist[i + 2].length > 1) { @@ -13333,7 +13684,7 @@ CSL.Util.Names.doNormalize = function (state, namelist, terminator, mode) { } return namelist.join("").replace(/[\u0009\u000a\u000b\u000c\u000d\u0020\ufeff\u00a0]+$/,"").replace(/\s*\-\s*/g, "-").replace(/[\u0009\u000a\u000b\u000c\u000d\u0020]+/g, " "); }; -CSL.Util.Names.doInitialize = function (state, namelist, terminator, mode) { +CSL.Util.Names.doInitialize = function (state, namelist, terminator) { var i, ilen, m, j, jlen, lst, n; for (i = 0, ilen = namelist.length; i < ilen; i += 2) { n = namelist[i]; @@ -13344,7 +13695,11 @@ CSL.Util.Names.doInitialize = function (state, namelist, terminator, mode) { if (!m && (!n.match(CSL.STARTSWITH_ROMANESQUE_REGEXP) && n.length > 1 && terminator.match("%s"))) { m = n.match(/(.)(.*)/); } - if (m && m[1] === m[1].toUpperCase()) { + if (m && m[2] && m[3]) { + m[1] = m[1] + m[2]; + m[2] = ""; + } + if (m && m[1].slice(0, 1) === m[1].slice(0, 1).toUpperCase()) { var extra = ""; if (m[2]) { var s = ""; @@ -13361,7 +13716,7 @@ CSL.Util.Names.doInitialize = function (state, namelist, terminator, mode) { extra = s.toLocaleLowerCase(); } } - namelist[i] = m[1].toLocaleUpperCase() + extra; + namelist[i] = m[1] + extra; if (i < (ilen - 1)) { if (terminator.match("%s")) { namelist[i] = terminator.replace("%s", namelist[i]); @@ -13379,7 +13734,7 @@ CSL.Util.Names.doInitialize = function (state, namelist, terminator, mode) { namelist.push(terminator); } } - } else if (n.match(CSL.ROMANESQUE_REGEXP)) { + } else if (n.match(CSL.ROMANESQUE_REGEXP) && (!m || !m[3])) { namelist[i] = " " + n; } } @@ -13409,7 +13764,7 @@ CSL.Util.Dates.year["long"] = function (state, num) { } return num.toString(); }; -CSL.Util.Dates.year.imperial = function (state, num, end, makeShort) { +CSL.Util.Dates.year.imperial = function (state, num, end) { var year = ""; if (!num) { if ("boolean" === typeof num) { @@ -13455,7 +13810,7 @@ CSL.Util.Dates.year.imperial = function (state, num, end, makeShort) { } if (state.transform.abbrevs['default']['number'][normalizedKey]) { label = state.transform.abbrevs['default']['number'][normalizedKey]; - }; + } year = label + (num - offset); } return year; @@ -13494,14 +13849,16 @@ CSL.Util.Dates.normalizeMonth = function (num, useSeason) { num = parseInt(num, 10); if (useSeason) { var res = {stub: "month-", num: num}; - if (res.num < 1 || res.num > 20) { + if (res.num < 1 || res.num > 24) { res.num = 0; - } else if (res.num > 16) { - res.stub = "season-"; - res.num = res.num - 16; - } else if (res.num > 12) { - res.stub = "season-"; - res.num = res.num - 12; + } else { + while (res.num > 16) { + res.num = res.num - 4; + } + if (res.num > 12) { + res.stub = "season-"; + res.num = res.num - 12; + } } ret = res; } else { @@ -13511,7 +13868,7 @@ CSL.Util.Dates.normalizeMonth = function (num, useSeason) { ret = num; } return ret; -} +}; CSL.Util.Dates.month = {}; CSL.Util.Dates.month.numeric = function (state, num) { var num = CSL.Util.Dates.normalizeMonth(num); @@ -13592,7 +13949,7 @@ CSL.Util.Sort.strip_prepositions = function (str) { }; CSL.Util.substituteStart = function (state, target) { var element_trace, display, bib_first, func, choose_start, if_start, nodetypes; - func = function (state, Item) { + func = function (state) { for (var i = 0, ilen = this.decorations.length; i < ilen; i += 1) { if ("@strip-periods" === this.decorations[i][0] && "true" === this.decorations[i][1]) { state.tmp.strip_periods += 1; @@ -13610,13 +13967,30 @@ CSL.Util.substituteStart = function (state, target) { if (("text" === this.name && !this.postponed_macro) || nodetypes.indexOf(this.name) > -1) { element_trace = function (state, Item, item) { if (state.tmp.element_trace.value() === "author" || "names" === this.name) { - if (item && item["author-only"]) { - state.tmp.element_trace.push("do-not-suppress-me"); - } else if (item && item["suppress-author"]) { + if (!state.tmp.just_looking && item && item["author-only"] && state.tmp.area !== "intext") { + if (!state.tmp.probably_rendered_something) { + } else { + state.tmp.element_trace.push("suppress-me"); + } + } + if (!state.tmp.just_looking && item && item["suppress-author"]) { + if (!state.tmp.probably_rendered_something) { + state.tmp.element_trace.push("suppress-me"); + } + } + } + else if ("date" === this.name) { + if (!state.tmp.just_looking && item && item["author-only"] && state.tmp.area !== "intext") { + if (state.tmp.probably_rendered_something) { + state.tmp.element_trace.push("suppress-me"); + } } } else { - if (item && item["author-only"]) { - state.tmp.element_trace.push("suppress-me"); + if (!state.tmp.just_looking && item && item["author-only"] && state.tmp.area !== "intext") { + if (!state.tmp.probably_rendered_something && state.tmp.can_block_substitute) { + } else { + state.tmp.element_trace.push("suppress-me"); + } } else if (item && item["suppress-author"]) { state.tmp.element_trace.push("do-not-suppress-me"); } @@ -13655,12 +14029,13 @@ CSL.Util.substituteStart = function (state, target) { choose_start = new CSL.Token("choose", CSL.START); CSL.Node.choose.build.call(choose_start, state, target); if_start = new CSL.Token("if", CSL.START); - func = function (Item,item) { + func = function () { if (state.tmp.can_substitute.value()) { return true; } return false; }; + if_start.tests ? {} : if_start.tests = []; if_start.tests.push(func); if_start.test = state.fun.match.any(this, state, if_start.tests); target.push(if_start); @@ -13677,13 +14052,15 @@ CSL.Util.substituteStart = function (state, target) { if (item) { position = item.position; } - if (!position) position = 0; + if (!position) { + position = 0; + } var positionMap = [ "first", "subsequent", "ibid", "ibid-with-locator" - ] + ]; var noteNumber = 0; if (item && item.noteIndex) { noteNumber = item.noteIndex; @@ -13714,22 +14091,22 @@ CSL.Util.substituteStart = function (state, target) { }; state.output.current.value().params = params; } - } + }; this.execs.push(func); } }; CSL.Util.substituteEnd = function (state, target) { - var func, bib_first_end, bib_other, if_end, choose_end, toplevel, hasval, author_substitute, str; + var func, bib_first_end, bib_other, if_end, choose_end, author_substitute, str; if (state.sys.variableWrapper && (this.hasVariable || (this.variables_real && this.variables_real.length))) { - func = function (state,Item) { + func = function (state) { if (!state.tmp.just_looking && !state.tmp.suppress_decorations) { state.output.endTag("variable_entry"); } - } + }; this.execs.push(func); } - func = function (state, Item) { + func = function (state) { for (var i = 0, ilen = this.decorations.length; i < ilen; i += 1) { if ("@strip-periods" === this.decorations[i][0] && "true" === this.decorations[i][1]) { state.tmp.strip_periods += -1; @@ -13741,14 +14118,14 @@ CSL.Util.substituteEnd = function (state, target) { state.build.render_nesting_level += -1; if (state.build.render_nesting_level === 0) { if (state.build.cls) { - func = function (state, Item) { + func = function (state) { state.output.endTag("bib_first"); }; this.execs.push(func); state.build.cls = false; } else if (state.build.area === "bibliography" && state.bibliography.opt["second-field-align"]) { bib_first_end = new CSL.Token("group", CSL.END); - func = function (state, Item) { + func = function (state) { if (!state.tmp.render_seen) { state.output.endTag("bib_first"); // closes bib_first } @@ -13757,7 +14134,7 @@ CSL.Util.substituteEnd = function (state, target) { target.push(bib_first_end); bib_other = new CSL.Token("group", CSL.START); bib_other.decorations = [["@display", "right-inline"]]; - func = function (state, Item) { + func = function (state) { if (!state.tmp.render_seen) { state.tmp.render_seen = true; state.output.startTag("bib_other", bib_other); @@ -13776,9 +14153,15 @@ CSL.Util.substituteEnd = function (state, target) { if ("names" === this.name || ("text" === this.name && this.variables_real !== "title")) { author_substitute = new CSL.Token("text", CSL.SINGLETON); func = function (state, Item) { - if (state.tmp.area !== "bibliography") return; - if ("string" !== typeof state.bibliography.opt["subsequent-author-substitute"]) return; - if (this.variables_real && !Item[this.variables_real]) return; + if (state.tmp.area !== "bibliography") { + return; + } + if ("string" !== typeof state.bibliography.opt["subsequent-author-substitute"]) { + return; + } + if (this.variables_real && !Item[this.variables_real]) { + return; + } if (state.tmp.substituted_variable !== this.variables_real) { return; } @@ -13842,7 +14225,9 @@ CSL.Util.substituteEnd = function (state, target) { } if (("text" === this.name && !this.postponed_macro) || ["number", "date", "names"].indexOf(this.name) > -1) { func = function (state, Item) { - state.tmp.element_trace.pop(); + if (state.tmp.element_trace.mystack.length>1) { + state.tmp.element_trace.pop(); + } }; this.execs.push(func); } @@ -13985,16 +14370,15 @@ CSL.Util.Suffixator.prototype.format = function (N) { } while ( N !== 0 ); return key; }; -CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) { - var val, m, i, ilen, j, jlen; - var debug = false; +CSL.Engine.prototype.processNumber = function (node, ItemObject, variable) { + var val; var me = this; - function normalizeFieldValue(str, defaultLabel) { + function normalizeFieldValue(str) { str = str.trim(); var m = str.match(/^([^ ]+)/); if (m && !CSL.STATUTE_SUBDIV_STRINGS[m[1]]) { var embeddedLabel = null; - if (variable === "locator" ) { + if (["locator", "locator-extra"].indexOf(variable) > -1) { if (ItemObject.label) { embeddedLabel = CSL.STATUTE_SUBDIV_STRINGS_REVERSE[ItemObject.label]; } else { @@ -14033,7 +14417,7 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) } info.joiningSuffix = joiningSuffix.replace(/\s*-\s*/, "-"); return info; - }; + } function fixupSubsections(elems) { for (var i=elems.length-2;i>-1;i-=2) { if (elems[i] === "-" @@ -14081,20 +14465,20 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) for (var j=lst.length-1;j>0;j--) { if (lst[j-1] && (!lst[j].match(/^[0-9]+([-;,:a-zA-Z]*)$/) || !lst[j-1].match(/^[0-9]+([-;,:a-zA-Z]*)$/))) { lst[j-1] = lst[j-1] + m[j-1] + lst[j]; - lst = lst.slice(0,j).concat(lst.slice(j+1)) - m = m.slice(0,j-1).concat(m.slice(j)) + lst = lst.slice(0,j).concat(lst.slice(j+1)); + m = m.slice(0,j-1).concat(m.slice(j)); } } if (m.length > 0) { var slug = m[0].trim(); var notAlabel = !CSL.STATUTE_SUBDIV_STRINGS[slug] || !me.getTerm(CSL.STATUTE_SUBDIV_STRINGS[slug]) - || (["locator", "number"].indexOf(variable) === -1 && CSL.STATUTE_SUBDIV_STRINGS[slug] !== variable); + || (["locator", "number", "locator-extra"].indexOf(variable) === -1 && CSL.STATUTE_SUBDIV_STRINGS[slug] !== variable); if (notAlabel) { if (i === 0) { m = m.slice(1); lst[0] = lst[0] + " " + slug + " " + lst[1]; - lst = lst.slice(0,1).concat(lst.slice(2)) + lst = lst.slice(0,1).concat(lst.slice(2)); } } else { origLabel = slug; @@ -14179,12 +14563,12 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) function fixLabelVisibility(values, groupStartPos, currentLabelInfo) { if (currentLabelInfo.label.slice(0, 4) !== "var:") { if (currentLabelInfo.pos === 0) { - if (variable === "locator" || variable === "number") { + if (["locator", "number", "locator-extra"].indexOf(variable) > -1) { if (!me.getTerm(CSL.STATUTE_SUBDIV_STRINGS[currentLabelInfo.label])) { values[currentLabelInfo.pos].labelVisibility = true; } } - if (["locator", "number"].indexOf(variable) === -1) { + if (["locator", "number", "locator-extra"].indexOf(variable) === -1) { if (CSL.STATUTE_SUBDIV_STRINGS[currentLabelInfo.label] !== variable) { values[0].labelVisibility = true; } @@ -14195,7 +14579,9 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) } } function setPluralsAndNumerics(values) { - if (values.length === 0) return; + if (values.length === 0) { + return; + } var groupStartPos = 0; var groupCount = 1; for (var i=1,ilen=values.length;i-1;j--) { - if (masterNode.decorations[j][0] === "@quotes") { - masterStyling.decorations = masterStyling.decorations.concat(masterNode.decorations.slice(j, j+1)); - masterNode.decorations = masterNode.decorations.slice(0, j).concat(masterNode.decorations.slice(j+1)) - } - } + masterStyling.decorations = masterNode.decorations; + masterNode.decorations = []; masterStyling.strings.prefix = masterNode.strings.prefix; masterNode.strings.prefix = ""; masterStyling.strings.suffix = masterNode.strings.suffix; @@ -14268,15 +14653,29 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) } return masterStyling; } - function stripHyphenBackslash(joiningSuffix) { - return joiningSuffix.replace("\\-", "-"); + function checkTerm(variable, val) { + var ret = true; + if (["locator", "locator-extra"].indexOf(variable) > -1) { + var label; + if (val.origLabel) { + label = val.origLabel; + } else { + label = val.label; + } + ret = !!me.getTerm(CSL.STATUTE_SUBDIV_STRINGS[label]); + } + return ret; + } + function checkPage(variable, val) { + return variable === "page" + || (["locator", "locator-extra"].indexOf(variable) > -1 && (["p."].indexOf(val.label) > -1 || ["p."].indexOf(val.origLabel) > -1)); } function fixupRangeDelimiter(variable, val, rangeDelimiter, isNumeric) { var isPage = checkPage(variable, val); var hasTerm = checkTerm(variable, val); if (hasTerm && rangeDelimiter === "-") { if (isNumeric) { - if (isPage || ["locator", "issue", "volume", "edition", "number"].indexOf(variable) > -1) { + if (isPage || ["locator", "locator-extra", "issue", "volume", "edition", "number"].indexOf(variable) > -1) { rangeDelimiter = me.getTerm("page-range-delimiter"); if (!rangeDelimiter) { rangeDelimiter = "\u2013"; @@ -14292,25 +14691,10 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) } return rangeDelimiter; } - function checkPage(variable, val) { - return variable === "page" - || (variable === "locator" && (["p."].indexOf(val.label) > -1 || ["p."].indexOf(val.origLabel) > -1)); - } - function checkTerm(variable, val) { - var ret = true; - if (variable === "locator") { - var label; - if (val.origLabel) { - label = val.origLabel; - } else { - label = val.label; - } - ret = !!me.getTerm(CSL.STATUTE_SUBDIV_STRINGS[label]); - } - return ret; - } function manglePageNumbers(values, i, currentInfo) { - if (i<1) return; + if (i<1) { + return; + } if (currentInfo.count !== 2) { return; } @@ -14350,13 +14734,17 @@ CSL.Engine.prototype.processNumber = function (node, ItemObject, variable, type) currentInfo.count = 0; } function fixRanges(values) { - if (!node) return; - if (["page", "page-first", "chapter-number", "collection-number", "edition", "issue", "number", "number-of-pages", "number-of-volumes", "volume", "locator"].indexOf(variable) === -1) return; + if (!node) { + return; + } + if (["page", "page-first", "chapter-number", "collection-number", "edition", "issue", "number", "number-of-pages", "number-of-volumes", "volume", "locator", "locator-extra"].indexOf(variable) === -1) { + return; + } var currentInfo = { count: 0, label: null, lastHadRangeDelimiter: false - } + }; for (var i=0,ilen=values.length; i": { @@ -14792,9 +15179,9 @@ CSL.Util.FlipFlopper = function(state) { "false": "true" } } - } - _nestingData["(\""] = _nestingData[" \""] - _nestingData["(\'"] = _nestingData[" \'"] + }; + _nestingData["(\""] = _nestingData[" \""]; + _nestingData["(\'"] = _nestingData[" \'"]; var localeOpenQuote = state.getTerm("open-quote"); var localeCloseQuote = state.getTerm("close-quote"); var localeOpenInnerQuote = state.getTerm("open-inner-quote"); @@ -14809,44 +15196,18 @@ CSL.Util.FlipFlopper = function(state) { _nestingData[localeOpenInnerQuote].opener = localeOpenInnerQuote; _nestingData[localeOpenInnerQuote].closer = localeCloseInnerQuote; } - var _nestingQuoteReverse = function() { - var ret = {}; - var keys = Object.keys(_nestingData); - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; - if (_nestingData[key].type === "quote") { - ret[_nestingData[key].closer] = _nestingData[key]; - } - } - return ret; - }(); - var _nestingDataAttr = function() { - var ret = {}; - var keys = Object.keys(_nestingData); - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; - if (_nestingData[key].type === "nocase") continue; - var attr = _nestingData[key].attr; - var outer = _nestingData[key].outer; - var inner = _nestingData[key].flipflop[_nestingData[key].outer]; - ret[attr + "/" + outer] = _nestingData[key]; - ret[attr + "/" + inner] = _nestingData[key]; - } - return ret; - }(); function _setOuterQuoteForm(quot) { var flip = { " \'": " \"", " \"": " \'", "(\"": "(\'", "(\'": "(\"" - } + }; _nestingData[quot].outer = "true"; _nestingData[flip[quot]].outer = "inner"; } function _getNestingOpenerParams(opener) { var openers = []; - var closer; var keys = Object.keys(_nestingData); for (var i = 0, l = keys.length; i < l; i++) { var key = keys[i]; @@ -14855,10 +15216,12 @@ CSL.Util.FlipFlopper = function(state) { } } var ret = _nestingData[opener]; - ret.opener = new RegExp("^(?:" + openers.map(function(str){return str.replace("(", "\\(")}).join("|") + ")"); + ret.opener = new RegExp("^(?:" + openers.map(function(str){ + return str.replace("(", "\\("); + }).join("|") + ")"); return ret; } - var _nestingParams = function() { + var _nestingParams = (function() { var ret = {}; var keys = Object.keys(_nestingData); for (var i = 0, l = keys.length; i < l; i++) { @@ -14866,8 +15229,8 @@ CSL.Util.FlipFlopper = function(state) { ret[key] = _getNestingOpenerParams(key); } return ret; - }() - var _tagRex = function() { + }()); + var _tagRex = (function() { var openers = []; var closers = []; var vals = {}; @@ -14880,24 +15243,18 @@ CSL.Util.FlipFlopper = function(state) { var closer = keys[i]; closers.push(closer); } - var all = openers.concat(closers).map(function(str){return str.replace("(", "\\(")}).join("|"); + var all = openers.concat(closers).map(function(str){ + return str.replace("(", "\\("); + }).join("|"); return { matchAll: new RegExp("((?:" + all + "))", "g"), splitAll: new RegExp("(?:" + all + ")", "g"), - open: new RegExp("(^(?:" + openers.map(function(str){return str.replace("(", "\\(")}).join("|") + ")$)"), + open: new RegExp("(^(?:" + openers.map(function(str){ + return str.replace("(", "\\("); + }).join("|") + ")$)"), close: new RegExp("(^(?:" + closers.join("|") + ")$)"), - } - }(); - function _nestingFix (tag, pos) { - return _pushNestingState(tag, pos); - } - function _pushNestingState(tag, pos) { - if (tag.match(_tagRex.open)) { - return _tryOpen(tag, pos); - } else { - return _tryClose(tag, pos); - } - } + }; + }()); function _tryOpen(tag, pos) { var params = _nestingState[_nestingState.length - 1]; if (!params || tag.match(params.opener)) { @@ -14909,7 +15266,7 @@ CSL.Util.FlipFlopper = function(state) { }); return false; } else { - _nestingState.pop() + _nestingState.pop(); _nestingState.push({ type: _nestingParams[tag].type, opener: _nestingParams[tag].opener, @@ -14924,14 +15281,14 @@ CSL.Util.FlipFlopper = function(state) { function _tryClose(tag, pos) { var params = _nestingState[_nestingState.length - 1]; if (params && tag === params.closer) { - _nestingState.pop() + _nestingState.pop(); if (params.type === "nocase") { return { nocase: { open: params.pos, close: pos } - } + }; } else { return false; } @@ -14947,6 +15304,16 @@ CSL.Util.FlipFlopper = function(state) { } } } + function _pushNestingState(tag, pos) { + if (tag.match(_tagRex.open)) { + return _tryOpen(tag, pos); + } else { + return _tryClose(tag, pos); + } + } + function _nestingFix (tag, pos) { + return _pushNestingState(tag, pos); + } function _doppelString(str) { var forcedSpaces = []; str = str.replace(/(]*(>)/g, "$1 $2$3;\"$4"); @@ -14963,7 +15330,7 @@ CSL.Util.FlipFlopper = function(state) { for (var i=0,ilen=match.length-1;i -1) { - match[i+1] = " " + match[i+1] + match[i+1] = " " + match[i+1]; forcedSpaces.push(true); } else { forcedSpaces.push(false); @@ -14974,23 +15341,11 @@ CSL.Util.FlipFlopper = function(state) { tags: match, strings: split, forcedSpaces: forcedSpaces - } + }; } - function _undoppelString(obj) { - var lst = obj.strings.slice(-1); - for (var i=obj.tags.length-1; i>-1; i+=-1) { - lst.push(obj.tags[i]); - lst.push(obj.strings[i]); - } - lst.reverse(); - return lst.join("|"); - } - var _TagReg = function(blob) { - this.set = set; - this.pair = pair; - this.pop = pop; + var TagReg = function(blob) { var _stack = []; - function set(tag) { + this.set = function (tag) { var attr = _nestingData[tag].attr; var decor = null; for (var i=_stack.length-1;i>-1;i--) { @@ -15001,11 +15356,13 @@ CSL.Util.FlipFlopper = function(state) { } } if (!decor) { - var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(blob.alldecor) + var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(blob.alldecor); outer: for (var i=allTheDecor.length-1;i>-1;i--) { var decorset = allTheDecor[i]; - if (!decorset) continue; + if (!decorset) { + continue; + } for (var j=decorset.length-1;j>-1;j--) { var _decor = decorset[j]; if (_decor[0] === attr) { @@ -15021,14 +15378,14 @@ CSL.Util.FlipFlopper = function(state) { decor = [attr, _nestingData[tag].flipflop[decor[1]]]; } _stack.push(decor); - } - function pair() { + }; + this.pair = function () { return _stack[_stack.length-1]; - } - function pop() { + }; + this.pop = function () { _stack.pop(); - } - } + }; + }; function _apostropheForce(tag, str) { if (tag === "\'") { if (str && str.match(/^[^\,\.\?\:\;\ ]/)) { @@ -15040,14 +15397,13 @@ CSL.Util.FlipFlopper = function(state) { return false; } function _undoppelToQueue(blob, doppel, leadingSpace) { - var TOP = blob; var firstString = true; - var tagReg = new _TagReg(blob); + var tagReg = new TagReg(blob); blob.blobs = []; function Stack (blob) { this.stack = [blob]; this.latest = blob; - this.addStyling = function(str, decor, forcedSpace) { + this.addStyling = function(str, decor) { if (firstString) { if (str.slice(0, 1) === " ") { str = str.slice(1); @@ -15071,17 +15427,19 @@ CSL.Util.FlipFlopper = function(state) { if (decor[0] === "@class" && decor[1] === "nodecor") { var newdecorset = []; var seen = {}; - var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(newblob.alldecor) + var allTheDecor = [state[state.tmp.area].opt.layout_decorations].concat(newblob.alldecor); for (var i=allTheDecor.length-1;i>-1;i--) { var _decorset = allTheDecor[i]; - if (!_decorset) continue; + if (!_decorset) { + continue; + } for (var j=_decorset.length-1;j>-1;j--) { var _olddecor = _decorset[j]; if (["@font-weight", "@font-style", "@font-variant"].indexOf(_olddecor[0]) > -1 && !seen[_olddecor[0]]) { if (decor[1] !== "normal") { newblob.decorations.push([_olddecor[0], "normal"]); - newdecorset.push([_olddecor[0], "normal"]) + newdecorset.push([_olddecor[0], "normal"]); } seen[_olddecor[0]] = true; } @@ -15110,11 +15468,11 @@ CSL.Util.FlipFlopper = function(state) { this.latest.blobs.push(child); } } - } + }; this.popStyling = function() { this.stack.pop(); - } - }; + }; + } var stack = new Stack(blob); if (doppel.strings.length) { var str = doppel.strings[0]; @@ -15136,16 +15494,18 @@ CSL.Util.FlipFlopper = function(state) { } } } - function processTags(blob) { + this.processTags = function (blob) { var str = blob.blobs; var leadingSpace = false; if (str.slice(0, 1) === " " && !str.match(/^\s+[\'\"]/)) { leadingSpace = true; } - var rex = new RegExp("(" + CSL.ROMANESQUE_REGEXP.source + ")\u2019(" + CSL.ROMANESQUE_REGEXP.source + ")", "g") + var rex = new RegExp("(" + CSL.ROMANESQUE_REGEXP.source + ")\u2019(" + CSL.ROMANESQUE_REGEXP.source + ")", "g"); var str = " " + str.replace(rex, "$1\'$2"); var doppel = _doppelString(str); - if (doppel.tags.length === 0) return; + if (doppel.tags.length === 0) { + return; + } var quoteFormSeen = false; for (var i=0,ilen=doppel.tags.length;i-1;i--) { - var tagPos = _nestingState[i].pos + var tagPos = _nestingState[i].pos; var tag = doppel.tags[tagPos]; if (tag === " \'" || tag === "\'") { doppel.strings[tagPos+1] = " \u2019" + doppel.strings[tagPos+1]; @@ -15229,16 +15589,9 @@ CSL.Util.FlipFlopper = function(state) { } } _undoppelToQueue(blob, doppel, leadingSpace); - } -} -CSL.Output.Formatters = new function () { - this.passthrough = passthrough; - this.lowercase = lowercase; - this.uppercase = uppercase; - this.sentence = sentence; - this.title = title; - this["capitalize-first"] = capitalizeFirst; - this["capitalize-all"] = capitalizeAll; + }; +}; +CSL.Output.Formatters = (function () { var rexStr = "(?:\u2018|\u2019|\u201C|\u201D| \"| \'|\"|\'|[-\u2013\u2014\/.,;?!:]|\\[|\\]|\\(|\\)|||<\/span>|<\/?(?:i|sc|b|sub|sup)>)"; var tagDoppel = new CSL.Doppeler(rexStr, function(str) { return str.replace(/(]*(>)/g, "$1 $2$3").replace(/(]*(>)/g, "$1 $2 $3;$4$5"); @@ -15251,8 +15604,8 @@ CSL.Output.Formatters = new function () { "": "", "": "", "": "" - } - function _capitalise (word, force) { + }; + function _capitalise (word) { var m = word.match(/(^\s*)((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))(.*)/); if (m && !(m[2].match(/^[\u0370-\u03FF]$/) && !m[3])) { return m[1] + m[2].toUpperCase() + m[3]; @@ -15281,21 +15634,7 @@ CSL.Output.Formatters = new function () { opener: "\u201C", closer: "\u201D" }, - } - function quoteFix (tag, positions) { - var m = tag.match(/(^(?:\u2018|\u2019|\u201C|\u201D|\"|\')|(?: \"| \')$)/); - if (m) { - return pushQuoteState(m[1], positions); - } - } - function pushQuoteState(tag, pos) { - var isOpener = ["\u201C", "\u2018", " \"", " \'"].indexOf(tag) > -1 ? true : false; - if (isOpener) { - return tryOpen(tag, pos); - } else { - return tryClose(tag, pos); - } - } + }; function tryOpen(tag, pos) { if (config.quoteState.length === 0 || tag === config.quoteState[config.quoteState.length - 1].opener) { config.quoteState.push({ @@ -15306,7 +15645,7 @@ CSL.Output.Formatters = new function () { return false; } else { var prevPos = config.quoteState[config.quoteState.length-1].pos; - config.quoteState.pop() + config.quoteState.pop(); config.quoteState.push({ opener: quoteParams[tag].opener, closer: quoteParams[tag].closer, @@ -15317,11 +15656,25 @@ CSL.Output.Formatters = new function () { } function tryClose(tag, pos) { if (config.quoteState.length > 0 && tag === config.quoteState[config.quoteState.length - 1].closer) { - config.quoteState.pop() + config.quoteState.pop(); } else { return pos; } } + function pushQuoteState(tag, pos) { + var isOpener = ["\u201C", "\u2018", " \"", " \'"].indexOf(tag) > -1 ? true : false; + if (isOpener) { + return tryOpen(tag, pos); + } else { + return tryClose(tag, pos); + } + } + function quoteFix (tag, positions) { + var m = tag.match(/(^(?:\u2018|\u2019|\u201C|\u201D|\"|\')|(?: \"| \')$)/); + if (m) { + return pushQuoteState(m[1], positions); + } + } if (config.doppel.strings.length && config.doppel.strings[0].trim()) { config.doppel.strings[0] = config.capitaliseWords(config.doppel.strings[0], 0, config.doppel.tags[0]); } @@ -15404,7 +15757,7 @@ CSL.Output.Formatters = new function () { tagState: [], afterPunct: null, isFirst: null - } + }; return _textcaseEngine(config, string); } function uppercase(state, string) { @@ -15424,7 +15777,7 @@ CSL.Output.Formatters = new function () { tagState: [], afterPunct: null, isFirst: null - } + }; return _textcaseEngine(config, string); } function sentence(state, string) { @@ -15449,7 +15802,7 @@ CSL.Output.Formatters = new function () { tagState: [], afterPunct: null, isFirst: true - } + }; return _textcaseEngine(config, string); } function title(state, string) { @@ -15462,7 +15815,9 @@ CSL.Output.Formatters = new function () { var words = wordle.strings; for (var j=0,jlen=words.length;j 1 && !word.toLowerCase().match(config.skipWordsRex)) { words[j] = _capitalise(words[j]); } else if (j === (words.length - 1) && followingTag === "-") { @@ -15477,7 +15832,7 @@ CSL.Output.Formatters = new function () { config.lastWordPos = { strings: i, words: j - } + }; } str = wordDoppel.join(wordle); } @@ -15487,7 +15842,7 @@ CSL.Output.Formatters = new function () { tagState: [], afterPunct: false, isFirst: true - } + }; return _textcaseEngine(config, string); } function capitalizeFirst(state, string) { @@ -15511,7 +15866,7 @@ CSL.Output.Formatters = new function () { tagState: [], afterPunct: null, isFirst: true - } + }; return _textcaseEngine(config, string); } function capitalizeAll (state, string) { @@ -15531,10 +15886,19 @@ CSL.Output.Formatters = new function () { tagState: [], afterPunct: null, isFirst: null - } + }; return _textcaseEngine(config, string); } -} + return { + passthrough: passthrough, + lowercase: lowercase, + uppercase: uppercase, + sentence: sentence, + title: title, + "capitalize-first": capitalizeFirst, + "capitalize-all": capitalizeAll + }; +}()); CSL.Output.Formats = function () {}; CSL.Output.Formats.prototype.html = { "text_escape": function (text) { @@ -15694,7 +16058,7 @@ CSL.Output.Formats.prototype.text = { "@display/indent": function (state, str) { return "\n "+str; }, - "@showid/true": function (state, str, cslid) { + "@showid/true": function (state, str) { return str; }, "@URL/true": function (state, str) { @@ -15766,7 +16130,7 @@ CSL.Output.Formats.prototype.rtf = { "@display/indent": function (state, str) { return "\n\\tab "+str+"\\line\r\n"; }, - "@showid/true": function (state, str, cslid) { + "@showid/true": function (state, str) { if (!state.tmp.just_looking && ! state.tmp.suppress_decorations) { var prePunct = ""; if (str) { @@ -15856,7 +16220,7 @@ CSL.Output.Formats.prototype.asciidoc = { "@display/indent": function (state, str) { return " " + str; }, - "@showid/true": function (state, str, cslid) { + "@showid/true": function (state, str) { if (!state.tmp.just_looking && !state.tmp.suppress_decorations && this.params && "string" === typeof str) { var prePunct = ""; if (str) { @@ -15968,7 +16332,7 @@ CSL.Output.Formats.prototype.fo = { "@display/indent": function (state, str) { return "" + str + "\n"; }, - "@showid/true": function (state, str, cslid) { + "@showid/true": function (state, str) { if (!state.tmp.just_looking && !state.tmp.suppress_decorations && this.params && "string" === typeof str) { var prePunct = ""; if (str) { @@ -15997,9 +16361,74 @@ CSL.Output.Formats.prototype.fo = { return "" + str + ""; } }; +CSL.Output.Formats.prototype.latex = { + "text_escape": function (text) { + if (!text) { + text = ""; + } + return text; + }, + "bibstart": "\\begin{thebibliography}{4}", + "bibend": "\end{thebibliography}", + "@font-style/italic": "{\\em %%STRING%%}", + "@font-style/oblique": false, + "@font-style/normal": false, + "@font-variant/small-caps": false, + "@passthrough/true": CSL.Output.Formatters.passthrough, + "@font-variant/normal": false, + "@font-weight/bold": "{\\bf %%STRING%%}", + "@font-weight/normal": false, + "@font-weight/light": false, + "@text-decoration/none": false, + "@text-decoration/underline": false, + "@vertical-align/baseline": false, + "@vertical-align/sup": false, + "@vertical-align/sub": false, + "@strip-periods/true": CSL.Output.Formatters.passthrough, + "@strip-periods/false": CSL.Output.Formatters.passthrough, + "@quotes/true": function (state, str) { + if ("undefined" === typeof str) { + return state.getTerm("open-quote"); + } + return state.getTerm("open-quote") + str + state.getTerm("close-quote"); + }, + "@quotes/inner": function (state, str) { + if ("undefined" === typeof str) { + return "\u2019"; + } + return state.getTerm("open-inner-quote") + str + state.getTerm("close-inner-quote"); + }, + "@quotes/false": false, + "@cite/entry": function (state, str) { + return state.sys.wrapCitationEntry(str, this.item_id, this.locator_txt, this.suffix_txt); + }, + "@bibliography/entry": function (state, str) { + return "\\bibitem{" + state.sys.embedBibliographyEntry(this.item_id) + "}\n"; + }, + "@display/block": function (state, str) { + return "\n"+str; + }, + "@display/left-margin": function (state, str) { + return str; + }, + "@display/right-inline": function (state, str) { + return str; + }, + "@display/indent": function (state, str) { + return "\n "+str; + }, + "@showid/true": function (state, str, cslid) { + return str; + }, + "@URL/true": function (state, str) { + return str; + }, + "@DOI/true": function (state, str) { + return str; + } +}; CSL.Output.Formats = new CSL.Output.Formats(); CSL.Registry = function (state) { - var pos, len, ret, i, ilen; this.debug = false; this.state = state; this.registry = {}; @@ -16128,7 +16557,7 @@ CSL.Registry.prototype.dodeletes = function (myhash) { for (var k = this.registry[key].siblings.length - 1; k > -1; k += -1) { var siblingID = this.registry[key].siblings.pop(); if (removeIDs.indexOf(siblingID) === -1) { - buffer.push(siblingID) + buffer.push(siblingID); } } for (var k = buffer.length - 1; k > -1; k += -1) { @@ -16148,7 +16577,7 @@ CSL.Registry.prototype.dodeletes = function (myhash) { } }; CSL.Registry.prototype.doinserts = function (mylist) { - var len, pos, item, Item, akey, newitem, abase, j, jlen, k, klen, i, ilen; + var item, Item, akey, newitem, abase, i, ilen; if ("string" === typeof mylist) { mylist = [mylist]; } @@ -16184,7 +16613,7 @@ CSL.Registry.prototype.doinserts = function (mylist) { } }; CSL.Registry.prototype.rebuildlist = function (nosort) { - var count, len, pos, item, Item; + var len, pos, item, Item; if (!nosort) { this.reflist_inserts = []; len = this.mylist.length; @@ -16210,7 +16639,7 @@ CSL.Registry.prototype.rebuildlist = function (nosort) { } }; CSL.Registry.prototype.dorefreshes = function () { - var key, regtoken, Item, old_akey, akey, abase; + var key, regtoken, Item, akey, abase; for (var key in this.refreshes) { regtoken = this.registry[key]; if (!regtoken) { @@ -16229,7 +16658,7 @@ CSL.Registry.prototype.dorefreshes = function () { if (this.ambigresets[akkey] === 1) { var loneKey = this.ambigcites[akey][0]; var Item = this.state.refetchItem(loneKey); - this.registry[loneKey].disambig = new CSL.AmbigConfig; + this.registry[loneKey].disambig = new CSL.AmbigConfig(); this.state.tmp.disambig_settings = false; var akey = CSL.getAmbiguousCite.call(this.state, Item); var abase = CSL.getAmbigConfig.call(this.state); @@ -16245,8 +16674,7 @@ CSL.Registry.prototype.dorefreshes = function () { } }; CSL.Registry.prototype.setdisambigs = function () { - var akey, key, pos, len, id; - for (akey in this.ambigsTouched) { + for (var akey in this.ambigsTouched) { this.state.disambiguate.run(akey); } this.ambigsTouched = {}; @@ -16284,18 +16712,21 @@ CSL.Registry.prototype._insertItem = function(element, array) { return array; }; CSL.Registry.prototype._locationOf = function(element, array, start, end) { - if (array.length === 0) + if (array.length === 0) { return -1; + } start = start || 0; end = end || array.length; var pivot = (start + end) >> 1; // should be faster than dividing by 2 var c = this.sorter.compareKeys(element, array[pivot]); - if (end - start <= 1) return c == -1 ? pivot - 1 : pivot; + if (end - start <= 1) { + return c == -1 ? pivot - 1 : pivot; + } switch (c) { case -1: return this._locationOf(element, array, start, pivot); case 0: return pivot; case 1: return this._locationOf(element, array, pivot, end); - }; + } }; CSL.Registry.prototype.sorttokens = function (nosort) { var len, item, Item, pos; @@ -16399,11 +16830,10 @@ CSL.Registry.prototype.registerAmbigToken = function (akey, id, ambig_config) { this.ambigcites[akey].push("" + id); } this.registry[id].ambig = akey; - var dome = false; this.registry[id].disambig = CSL.cloneAmbigConfig(ambig_config); }; CSL.getSortKeys = function (Item, key_type) { - var area, root, extension, strip_prepositions, use_parallels, len, pos; + var area, root, extension, strip_prepositions, len, pos; area = this.tmp.area; root = this.tmp.root; extension = this.tmp.extension; @@ -16429,7 +16859,7 @@ CSL.getSortKeys = function (Item, key_type) { return this[key_type].keys; }; CSL.Registry.NameReg = function (state) { - var pkey, ikey, skey, floor, ceiling, dagopt, gdropt, ret, pos, items, strip_periods, set_keys, evalname, delitems, addname, key, myitems, i, ilen; + var pkey, ikey, skey, dagopt, gdropt, items, strip_periods, set_keys, evalname, delitems, addname, myitems; this.state = state; this.namereg = {}; this.nameind = {}; @@ -16454,7 +16884,7 @@ CSL.Registry.NameReg = function (state) { } }; evalname = function (item_id, nameobj, namenum, request_base, form, initials) { - var pos, len, items, param; + var param; if (state.tmp.area.slice(0, 12) === "bibliography" && !form) { if ("string" === typeof initials) { return 1; @@ -16517,7 +16947,7 @@ CSL.Registry.NameReg = function (state) { } }; delitems = function (ids) { - var item, pos, len, posA, posB, id, fullkey, llen, ppos, otherid; + var pos, len, posB, id, fullkey; if ("string" === typeof ids || "number" === typeof ids) { ids = ["" + ids]; } @@ -16651,7 +17081,7 @@ CSL.Registry.NameReg = function (state) { this.delitems = delitems; this.evalname = evalname; }; -CSL.Registry.CitationReg = function (state) { +CSL.Registry.CitationReg = function () { this.citationById = {}; this.citationByIndex = []; }; @@ -16673,7 +17103,7 @@ CSL.Disambiguation.prototype.run = function(akey) { } }; CSL.Disambiguation.prototype.runDisambig = function () { - var pos, len, ppos, llen, pppos, lllen, ismax; + var ismax; this.initGivens = true; while (this.lists.length) { this.gnameset = 0; @@ -16684,7 +17114,6 @@ CSL.Disambiguation.prototype.runDisambig = function () { if (!this.base) { this.base = this.lists[0][0]; } - var names_used = []; ismax = this.incrementDisambig(); this.scanItems(this.lists[0]); this.evalScan(ismax); @@ -16693,7 +17122,7 @@ CSL.Disambiguation.prototype.runDisambig = function () { } }; CSL.Disambiguation.prototype.scanItems = function (list) { - var pos, len, Item, otherItem, ItemCite, ignore, base; + var pos, len, otherItem; this.Item = list[1][0]; this.ItemCite = CSL.getAmbiguousCite.call(this.state, this.Item, this.base, true); this.scanlist = list[1]; @@ -16725,7 +17154,7 @@ CSL.Disambiguation.prototype.evalScan = function (maxed) { } }; CSL.Disambiguation.prototype.disNames = function (ismax) { - var pos, len, mybase, i, ilen; + var i, ilen; if (this.clashes[1] === 0 && this.nonpartners.length === 1) { this.captureStepToBase(); this.state.registry.registerAmbigToken(this.akey, "" + this.nonpartners[0].id, this.betterbase); @@ -16760,7 +17189,6 @@ CSL.Disambiguation.prototype.disNames = function (ismax) { } }; CSL.Disambiguation.prototype.disExtraText = function () { - var pos, len, mybase; var done = false; if (this.clashes[1] === 0 && this.nonpartners.length < 2) { done = true; @@ -16798,7 +17226,7 @@ CSL.Disambiguation.prototype.disExtraText = function () { } }; CSL.Disambiguation.prototype.disYears = function () { - var pos, len, tokens, token, item; + var pos, len, tokens, token; tokens = []; var base = this.lists[this.listpos][0]; if (this.clashes[1]) { @@ -16825,14 +17253,12 @@ CSL.Disambiguation.prototype.disYears = function () { this.lists[this.listpos] = [this.betterbase, []]; }; CSL.Disambiguation.prototype.incrementDisambig = function () { - var val; if (this.initGivens) { this.initGivens = false; return false; } var maxed = false; var increment_names = true; - var increment_givens = true; if ("disNames" === this.modes[this.modeindex]) { increment_names = false; if ("number" !== typeof this.givensMax) { @@ -16868,8 +17294,6 @@ CSL.Disambiguation.prototype.incrementDisambig = function () { this.gnameset += 1; this.base.names[this.gnameset] = 1; this.gname = 0; - } else { - var increment_mode = true; } } if (("number" !== typeof this.namesetsMax || this.namesetsMax === -1 || this.gnameset === this.namesetsMax) @@ -16895,7 +17319,6 @@ CSL.Disambiguation.prototype.initVars = function (akey) { if (!myIds || !myIds.length) { return false; } - var Item = false; var myItem = this.state.refetchItem("" + myIds[0]); this.getCiteData(myItem); this.base = CSL.getAmbigConfig.call(this.state); @@ -16964,7 +17387,7 @@ CSL.Disambiguation.prototype.padBase = function (base) { } } } -} +}; CSL.Disambiguation.prototype.configModes = function () { var dagopt, gdropt; this.modes = []; @@ -16997,7 +17420,6 @@ CSL.Disambiguation.prototype.getCiteData = function(Item, base) { if (base.names.length < this.base.names.length) { this.base = base; } - var update = false; for (var i = 0, ilen = base.names.length; i < ilen; i += 1) { if (base.names[i] > this.base.names[i]) { this.base.givens[i] = base.givens[i].slice(); @@ -17033,7 +17455,7 @@ CSL.Engine.prototype.getJurisdictionList = function (jurisdiction) { jurisdictionList.push("us"); } return jurisdictionList; -} +}; CSL.Engine.prototype.retrieveAllStyleModules = function (jurisdictionList) { var ret = {}; var preferences = this.locale[this.opt.lang].opts["jurisdiction-preference"]; @@ -17043,21 +17465,24 @@ CSL.Engine.prototype.retrieveAllStyleModules = function (jurisdictionList) { var preference = preferences[i]; for (var j=0,jlen=jurisdictionList.length;j