From d3bc1703c3df52814a777696fdd3589a93813eae Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Sat, 11 Jul 2015 13:35:03 -0500 Subject: [PATCH] Update citeproc-js to 1.1.39 Re https://github.com/zotero/zotero/pull/794#issuecomment-120564983 --- chrome/content/zotero/xpcom/citeproc.js | 213 ++++++++++++++---------- 1 file changed, 127 insertions(+), 86 deletions(-) diff --git a/chrome/content/zotero/xpcom/citeproc.js b/chrome/content/zotero/xpcom/citeproc.js index 30f3c945ff..f356d86b74 100644 --- a/chrome/content/zotero/xpcom/citeproc.js +++ b/chrome/content/zotero/xpcom/citeproc.js @@ -80,7 +80,7 @@ if (!Array.indexOf) { }; } var CSL = { - PROCESSOR_VERSION: "1.1.25", + PROCESSOR_VERSION: "1.1.39", CONDITION_LEVEL_TOP: 1, CONDITION_LEVEL_BOTTOM: 2, PLAIN_HYPHEN_REGEX: /(?:[^\\]-|\u2013)/, @@ -194,15 +194,22 @@ var CSL = { ], checkNestedBraceOpen: new RegExp(".*\\("), checkNestedBraceClose: new RegExp(".*\\)"), + MULTI_FIELDS: ["event", "publisher", "publisher-place", "event-place", "title", "container-title", "collection-title", "authority","edition","genre","title-short","medium","jurisdiction","archive","archive-place"], LangPrefsMap: { "title":"titles", "title-short":"titles", + "event":"titles", + "genre":"titles", + "medium":"titles", "container-title":"journals", "collection-title":"journals", + "archive":"journals", "publisher":"publishers", "authority":"publishers", "publisher-place": "places", "event-place": "places", + "archive-place": "places", + "jurisdiction": "places", "number": "number", "edition":"number", "issue":"number", @@ -251,7 +258,6 @@ var CSL = { MARK_TRAILING_NAMES: true, POSITION_TEST_VARS: ["position", "first-reference-note-number", "near-note"], AREAS: ["citation", "citation_sort", "bibliography", "bibliography_sort"], - MULTI_FIELDS: ["event", "publisher", "publisher-place", "event-place", "title", "container-title", "collection-title", "authority","edition","genre","title-short","medium","jurisdiction","archive","archive-place"], CITE_FIELDS: ["first-reference-note-number", "locator", "locator-extra"], MINIMAL_NAME_FIELDS: ["literal", "family"], SWAPPING_PUNCTUATION: [".", "!", "?", ":", ","], @@ -827,6 +833,7 @@ CSL.expandMacro = function (macro_key_token, target) { macro_key_token.cslid = macroid; if (CSL.MODULE_MACROS[mkey]) { macro_key_token.juris = mkey; + macro_key_token.alt_macro = alt_macro; this.opt.update_mode = CSL.POSITION; } CSL.Node.group.build.call(macro_key_token, this, target); @@ -845,20 +852,7 @@ CSL.expandMacro = function (macro_key_token, target) { while (next < state.macros[macro_name].length) { next = CSL.tokenExec.call(state, state.macros[macro_name][next], Item, item); } - var flag = state.tmp.group_context.value(); - if (((flag[1] && !flag[2]) || (!flag[0] && !flag[1])) && alt_macro) { - flag[1] = false; - var mytarget = CSL.getMacroTarget.call(state, alt_macro); - if (mytarget) { - var macro_nodes = state.sys.xml.getNodesByName(state.cslXml, 'macro', alt_macro); - CSL.buildMacro.call(state, mytarget, macro_nodes); - CSL.configureMacro.call(state, mytarget); - } - var next = 0; - while (next < state.macros[alt_macro].length) { - next = CSL.tokenExec.call(state, state.macros[alt_macro][next], Item, item); - } - } + CSL.runAltMacro(state, alt_macro, Item, item); } }(mkey, alt_macro); var text_node = new CSL.Token("text", CSL.SINGLETON); @@ -884,19 +878,31 @@ CSL.expandMacro = function (macro_key_token, target) { this.build.macro_stack.pop(); }; CSL.getMacroTarget = function (mkey) { - var mytarget; + var mytarget = false; if (this.build.extension) { mytarget = this[this.build.root + this.build.extension].tokens; - } else { - if (!this.macros[mkey]) { - mytarget = []; - this.macros[mkey] = mytarget; - } else { - mytarget = false; - } + } else if (!this.macros[mkey]) { + mytarget = []; + this.macros[mkey] = mytarget; } return mytarget; } +CSL.runAltMacro = function (state, alt_macro, Item, item) { + var flag = state.tmp.group_context.value(); + if (((flag[1] && !flag[2]) || (!flag[0] && !flag[1])) && alt_macro) { + flag[1] = false; + var mytarget = CSL.getMacroTarget.call(state, alt_macro); + if (mytarget) { + var macro_nodes = state.sys.xml.getNodesByName(state.cslXml, 'macro', alt_macro); + CSL.buildMacro.call(state, mytarget, macro_nodes); + CSL.configureMacro.call(state, mytarget); + } + var next = 0; + while (next < state.macros[alt_macro].length) { + next = CSL.tokenExec.call(state, state.macros[alt_macro][next], Item, item); + } + } +} CSL.buildMacro = function (mytarget, macro_nodes) { var builder = CSL.makeBuilder(this, mytarget); var mynode; @@ -1456,7 +1462,7 @@ CSL.Engine = function (sys, style, lang, forceLang) { this.localeConfigure(langspec); function makeRegExp(lst) { var lst = lst.slice(); - var ret = new RegExp( "((?:[?!:]*\\s+|-|^)(?:" + lst.join("|") + ")(?=[!?:]*\\s+|-|$))" ); + var ret = new RegExp( "(?:(?:[?!:]*\\s+|-|^)(?:" + lst.join("|") + ")(?=[!?:]*\\s+|-|$))", "g"); return ret; } this.locale[this.opt.lang].opts["skip-words-regexp"] = makeRegExp(this.locale[this.opt.lang].opts["skip-words"]); @@ -1759,6 +1765,24 @@ CSL.Engine.prototype.retrieveItem = function (id) { } } } + if (this.sys.getLanguageName && Item.language) { + if (Item.language) { + Item.language = Item.language.toLowerCase(); + var lst = Item.language.split("<"); + if (lst.length > 0) { + var languageName = this.sys.getLanguageName(lst[0]); + if (languageName) { + Item["language-name"] = languageName; + } + } + if (lst.length === 2) { + var originalLanguage = this.sys.getLanguageName(lst[1]); + if (originalLanguage) { + Item["language-name-original"] = originalLanguage; + } + } + } + } if (Item.page) { Item["page-first"] = Item.page; var num = "" + Item.page; @@ -2430,7 +2454,7 @@ CSL.Output.Queue.prototype.startTag = function (name, token) { this.openLevel(name); }; CSL.Output.Queue.prototype.endTag = function (name) { - this.closeLevel(); + this.closeLevel(name); this.popFormats(); }; CSL.Output.Queue.prototype.openLevel = function (token, ephemeral) { @@ -4728,23 +4752,6 @@ CSL.getBibliographyEntries = function (bibsection) { } else { topblobs = this.output.queue[0].blobs[0].blobs; } - for (j = topblobs.length - 1; j > -1; j += -1) { - if (topblobs[j].blobs && topblobs[j].blobs.length !== 0) { - var last_locale = this.tmp.cite_locales[this.tmp.cite_locales.length - 1]; - var suffix; - if (this.tmp.cite_affixes[this.tmp.area][last_locale]) { - suffix = this.tmp.cite_affixes[this.tmp.area][last_locale].suffix; - } else { - suffix = this.bibliography.opt.layout_suffix; - } - chr = suffix.slice(0, 1); - if (chr && topblobs[j].strings.suffix.slice(-1) === chr) { - topblobs[j].strings.suffix = topblobs[j].strings.suffix.slice(0, -1); - } - topblobs[j].strings.suffix += suffix; - break; - } - } topblobs[0].strings.prefix = this.bibliography.opt.layout_prefix + topblobs[0].strings.prefix; } for (var j=0,jlen=this.output.queue.length;j -1) { + if (CSL.MULTI_FIELDS.indexOf(this.variables_real[0]) > -1 + || ["language-name", "language-name-original"].indexOf(this.variables_real[0]) > -1) { var abbrevfam = this.variables[0]; var abbrfall = false; var altvar = false; @@ -9457,21 +9486,19 @@ CSL.Attributes["@variable"] = function (state, arg) { output = false; for (var i=0,ilen=this.variables.length;i -1 && "string" === typeof Item[variable] && "names" === this.name) { var creatorParent = { - family:Item[variable], - isInstitution:true, + literal:Item[variable], multi:{ _key:{} } }; if (Item.multi && Item.multi._keys && Item.multi._keys[variable]) { for (var langTag in Item.multi._keys[variable]) { - creatorChild = { - family:Item.multi._keys[variable][langTag], - isInstitution:true + var creatorChild = { + literal:Item.multi._keys[variable][langTag] } creatorParent.multi._key[langTag] = creatorChild; } @@ -10859,7 +10886,7 @@ CSL.Transform = function (state) { if (CSL.NUMERIC_VARIABLES.indexOf(myabbrev_family) > -1) { myabbrev_family = "number"; } - if (["publisher-place", "event-place", "jurisdiction", "archive-place"].indexOf(myabbrev_family) > -1) { + if (["publisher-place", "event-place", "jurisdiction", "archive-place", "language-name", "language-name-original"].indexOf(myabbrev_family) > -1) { myabbrev_family = "place"; } if (["publisher", "authority"].indexOf(myabbrev_family) > -1) { @@ -12040,7 +12067,7 @@ CSL.Util.substituteEnd = function (state, target) { bib_first_end = new CSL.Token("group", CSL.END); func = function (state, Item) { if (!state.tmp.render_seen) { - state.output.endTag(); // closes bib_first + state.output.endTag("bib_first"); // closes bib_first } }; bib_first_end.execs.push(func); @@ -13003,14 +13030,28 @@ CSL.Output.Formatters.title = function (state, string) { } return word; } + function splitme (str, rex) { + var res, seps = str.match(rex); + if (seps) { + var splits = str.split(rex); + res = [splits[0]]; + for (var i=0; i 2 && !lst[lst.length-1]) { @@ -13279,16 +13320,16 @@ CSL.Output.Formats.prototype.rtf = { .replace("\t", "\\tab{}", "g"); }, "@passthrough/true": CSL.Output.Formatters.passthrough, - "@font-style/italic":"\\i %%STRING%%\\i0{}", - "@font-style/normal":"\\i0{}%%STRING%%\\i{}", - "@font-style/oblique":"\\i %%STRING%%\\i0{}", - "@font-variant/small-caps":"\\scaps %%STRING%%\\scaps0{}", - "@font-variant/normal":"\\scaps0{}%%STRING%%\\scaps{}", - "@font-weight/bold":"\\b %%STRING%%\\b0{}", - "@font-weight/normal":"\\b0{}%%STRING%%\\b{}", + "@font-style/italic":"{\\i{}%%STRING%%}", + "@font-style/normal":"{\\i0{}%%STRING%%}", + "@font-style/oblique":"{\\i{}%%STRING%%}", + "@font-variant/small-caps":"{\\scaps %%STRING%%}", + "@font-variant/normal":"{\\scaps0{}%%STRING%%}", + "@font-weight/bold":"{\\b{}%%STRING%%}", + "@font-weight/normal":"{\\b0{}%%STRING%%}", "@font-weight/light":false, "@text-decoration/none":false, - "@text-decoration/underline":"\\ul %%STRING%%\\ul0{}", + "@text-decoration/underline":"{\\ul{}%%STRING%%}", "@vertical-align/baseline":false, "@vertical-align/sup":"\\super %%STRING%%\\nosupersub{}", "@vertical-align/sub":"\\sub %%STRING%%\\nosupersub{}", @@ -14604,4 +14645,4 @@ CSL.parseParticles = function(){ apostropheNormalizer(name, true); } } -}(); \ No newline at end of file +}();