Update citeproc-js

This commit is contained in:
Simon Kornblith 2013-11-19 02:13:54 -05:00
parent 322755e745
commit 481e00bfc8

View file

@ -57,7 +57,7 @@ if (!Array.indexOf) {
}; };
} }
var CSL = { var CSL = {
PROCESSOR_VERSION: "1.0.502", PROCESSOR_VERSION: "1.0.508",
CONDITION_LEVEL_TOP: 1, CONDITION_LEVEL_TOP: 1,
CONDITION_LEVEL_BOTTOM: 2, CONDITION_LEVEL_BOTTOM: 2,
PLAIN_HYPHEN_REGEX: /(?:[^\\]-|\u2013)/, PLAIN_HYPHEN_REGEX: /(?:[^\\]-|\u2013)/,
@ -1597,14 +1597,18 @@ CSL.DateParser = function () {
thedate["date-parts"][0].push(thedate[part]); thedate["date-parts"][0].push(thedate[part]);
delete thedate[part]; delete thedate[part];
} }
thedate["date-parts"].push([]);
for (i = 0, ilen = slicelen; i < ilen; i += 1) { for (i = 0, ilen = slicelen; i < ilen; i += 1) {
part = ["year_end", "month_end", "day_end"][i]; part = ["year_end", "month_end", "day_end"][i];
if (thedate[part] && thedate["date-parts"].length === 1) { if (!thedate[part]) {
thedate["date-parts"].push([]); break;
} }
thedate["date-parts"][1].push(thedate[part]); thedate["date-parts"][1].push(thedate[part]);
delete thedate[part]; delete thedate[part];
} }
if (thedate["date-parts"][0].length !== thedate["date-parts"][1].length) {
thedate["date-parts"].pop();
}
}; };
this.parseNumericDate = function (ret, delim, suff, txt) { this.parseNumericDate = function (ret, delim, suff, txt) {
var lst, i, ilen; var lst, i, ilen;
@ -1730,10 +1734,10 @@ CSL.Engine = function (sys, style, lang, forceLang) {
langspec = CSL.localeResolve(lang); langspec = CSL.localeResolve(lang);
this.opt.lang = langspec.best; this.opt.lang = langspec.best;
this.opt["default-locale"][0] = langspec.best; this.opt["default-locale"][0] = langspec.best;
this.locale = {};
if (!this.opt["default-locale-sort"]) { if (!this.opt["default-locale-sort"]) {
this.opt["default-locale-sort"] = this.opt["default-locale"][0]; this.opt["default-locale-sort"] = this.opt["default-locale"][0];
} }
this.locale = {};
this.localeConfigure(langspec); this.localeConfigure(langspec);
function makeRegExp(lst) { function makeRegExp(lst) {
var lst = lst.slice(); var lst = lst.slice();
@ -2714,7 +2718,7 @@ CSL.Output.Queue.prototype.append = function (str, tokname, notSerious, ignorePr
if (notSerious) { if (notSerious) {
ignorePredecessor = true; ignorePredecessor = true;
} }
if (this.state.tmp["doing-macro-with-date"]) { if (this.state.tmp["doing-macro-with-date"] && !notSerious) {
if (tokname !== "macro-with-date") { if (tokname !== "macro-with-date") {
return false; return false;
} }
@ -3475,7 +3479,6 @@ CSL.Engine.Opt = function () {
this["demote-non-dropping-particle"] = "display-and-sort"; this["demote-non-dropping-particle"] = "display-and-sort";
this["parse-names"] = true; this["parse-names"] = true;
this.citation_number_slug = false; this.citation_number_slug = false;
this.max_number_of_names = 0;
this.trigraph = "Aaaa00:AaAa00:AaAA00:AAAA00"; this.trigraph = "Aaaa00:AaAa00:AaAA00:AAAA00";
this.development_extensions = {}; this.development_extensions = {};
this.development_extensions.field_hack = true; this.development_extensions.field_hack = true;
@ -3512,6 +3515,7 @@ CSL.Engine.Opt = function () {
places:['orig'], places:['orig'],
number:['translat'] number:['translat']
}; };
this.has_layout_locale = false;
}; };
CSL.Engine.Tmp = function () { CSL.Engine.Tmp = function () {
this.names_max = new CSL.Stack(); this.names_max = new CSL.Stack();
@ -3606,6 +3610,9 @@ CSL.Engine.Citation = function (state) {
this.opt.layout_prefix = ""; this.opt.layout_prefix = "";
this.opt.layout_suffix = ""; this.opt.layout_suffix = "";
this.opt.layout_delimiter = ""; this.opt.layout_delimiter = "";
this.opt.sort_locales = [];
this.opt.max_number_of_names = 0;
this.root = "citation";
}; };
CSL.Engine.Bibliography = function () { CSL.Engine.Bibliography = function () {
this.opt = {}; this.opt = {};
@ -3618,6 +3625,9 @@ CSL.Engine.Bibliography = function () {
this.opt.layout_delimiter = ""; this.opt.layout_delimiter = "";
this.opt["line-spacing"] = 1; this.opt["line-spacing"] = 1;
this.opt["entry-spacing"] = 1; this.opt["entry-spacing"] = 1;
this.opt.sort_locales = [];
this.opt.max_number_of_names = 0;
this.root = "bibliography";
}; };
CSL.Engine.BibliographySort = function () { CSL.Engine.BibliographySort = function () {
this.tokens = []; this.tokens = [];
@ -3625,6 +3635,7 @@ CSL.Engine.BibliographySort = function () {
this.opt.sort_directions = []; this.opt.sort_directions = [];
this.keys = []; this.keys = [];
this.opt.topdecor = []; this.opt.topdecor = [];
this.root = "bibliography";
}; };
CSL.Engine.CitationSort = function () { CSL.Engine.CitationSort = function () {
this.tokens = []; this.tokens = [];
@ -3632,6 +3643,7 @@ CSL.Engine.CitationSort = function () {
this.opt.sort_directions = []; this.opt.sort_directions = [];
this.keys = []; this.keys = [];
this.opt.topdecor = []; this.opt.topdecor = [];
this.root = "citation";
}; };
CSL.Engine.prototype.previewCitationCluster = function (citation, citationsPre, citationsPost, newMode) { CSL.Engine.prototype.previewCitationCluster = function (citation, citationsPre, citationsPost, newMode) {
var oldMode = this.opt.mode; var oldMode = this.opt.mode;
@ -4962,14 +4974,23 @@ CSL.Engine.prototype.updateUncitedItems = function (idList, nosort) {
this.registry.renumber(); this.registry.renumber();
return this.registry.getSortedIds(); return this.registry.getSortedIds();
}; };
CSL.localeResolve = function (langstr) { CSL.localeResolve = function (langstr, defaultLocale) {
var ret, langlst; var ret, langlst;
if (!defaultLocale) {
defaultLocale = "en-US";
}
if (!langstr) {
langstr = defaultLocale;
}
ret = {}; ret = {};
langlst = langstr.split(/[\-_]/); langlst = langstr.split(/[\-_]/);
ret.base = CSL.LANG_BASES[langlst[0]]; ret.base = CSL.LANG_BASES[langlst[0]];
if ("undefined" === typeof ret.base) { if ("undefined" === typeof ret.base) {
CSL.debug("Warning: unknown locale "+langstr+", setting fallback to en-US"); CSL.debug("Warning: unknown locale "+langstr+", setting fallback to "+defaultLocale);
return {base:"en-US", best:langstr, bare:langlst[0]}; return {base:defaultLocale, best:langstr, bare:langlst[0]};
}
if (langlst.length === 1) {
ret.generic = true;
} }
if (langlst.length === 1 || langlst[1] === "x") { if (langlst.length === 1 || langlst[1] === "x") {
ret.best = ret.base.replace("_", "-"); ret.best = ret.base.replace("_", "-");
@ -6718,10 +6739,10 @@ CSL.NameOutput.prototype._truncateNameList = function (container, variable, inde
} else { } else {
lst = container[variable][index]; lst = container[variable][index];
} }
if (this.state.opt.max_number_of_names if (this.state[this.state[this.state.tmp.area].root].opt.max_number_of_names
&& lst.length > 50 && lst.length > 50
&& lst.length > (this.state.opt.max_number_of_names + 2)) { && lst.length > (this.state[this.state[this.state.tmp.area].root].opt.max_number_of_names + 2)) {
lst = lst.slice(0, this.state.opt.max_number_of_names + 2); lst = lst.slice(0, this.state[this.state[this.state.tmp.area].root].opt.max_number_of_names + 2);
} }
return lst; return lst;
}; };
@ -7701,14 +7722,22 @@ CSL.NameOutput.prototype._stripPeriods = function (tokname, str) {
return str; return str;
}; };
CSL.NameOutput.prototype._nonDroppingParticle = function (name) { CSL.NameOutput.prototype._nonDroppingParticle = function (name) {
var str = this._stripPeriods("family", name["non-dropping-particle"]); var ndp = name["non-dropping-particle"];
if (ndp && this.state.tmp.sort_key_flag) {
ndp = ndp.replace(/[\'\u2019]/, "");
}
var str = this._stripPeriods("family", ndp);
if (this.state.output.append(str, this.family_decor, true)) { if (this.state.output.append(str, this.family_decor, true)) {
return this.state.output.pop(); return this.state.output.pop();
} }
return false; return false;
}; };
CSL.NameOutput.prototype._droppingParticle = function (name, pos, j) { CSL.NameOutput.prototype._droppingParticle = function (name, pos, j) {
var str = this._stripPeriods("given", name["dropping-particle"]); var dp = name["dropping-particle"];
if (dp && this.state.tmp.sort_key_flag) {
dp = dp.replace(/[\'\u2019]/, "");
}
var str = this._stripPeriods("given", dp);
if (name["dropping-particle"] && name["dropping-particle"].match(/^et.?al[^a-z]$/)) { if (name["dropping-particle"] && name["dropping-particle"].match(/^et.?al[^a-z]$/)) {
if (this.name.strings["et-al-use-last"]) { if (this.name.strings["et-al-use-last"]) {
if ("undefined" === typeof j) { if ("undefined" === typeof j) {
@ -7813,10 +7842,10 @@ CSL.NameOutput.prototype._parseName = function (name) {
noparse = false; noparse = false;
} }
if (!name["non-dropping-particle"] && name.family && !noparse && name.given) { if (!name["non-dropping-particle"] && name.family && !noparse && name.given) {
m = name.family.match(/^((?:[a-z][ \'\u2019a-z]*[-|\s+|\'\u2019]|[ABDVL][^ ][-|\s+][a-z]*\s*|[ABDVL][^ ][^ ][-|\s+][a-z]*\s*))/); m = name.family.match(/^((?:[\'\u2019a-z][ \'\u2019a-z]*[-\s\'\u2019]+|[ABDVL][^ ][-\s]+[a-z]*\s*|[ABDVL][^ ][^ ][-\s]+[a-z]*\s*))/);
if (m) { if (m) {
name.family = name.family.slice(m[1].length); name.family = name.family.slice(m[1].length);
name["non-dropping-particle"] = m[1].replace(/\s+$/, ""); name["non-dropping-particle"] = m[1].replace(/\s+$/, "").replace("'", "\u2019");
} }
} }
if (!name.suffix && name.given) { if (!name.suffix && name.given) {
@ -8628,6 +8657,7 @@ CSL.Node.number = {
}; };
CSL.Node.sort = { CSL.Node.sort = {
build: function (state, target) { build: function (state, target) {
target = state[state.build.root + "_sort"].tokens;
if (this.tokentype === CSL.START) { if (this.tokentype === CSL.START) {
if (state.build.area === "citation") { if (state.build.area === "citation") {
state.parallel.use_parallels = false; state.parallel.use_parallels = false;
@ -8636,12 +8666,38 @@ CSL.Node.sort = {
state.build.area = state.build.root + "_sort"; state.build.area = state.build.root + "_sort";
state.build.extension = "_sort"; state.build.extension = "_sort";
var func = function (state, Item) { var func = function (state, Item) {
if (state.opt.has_layout_locale) {
var langspec = CSL.localeResolve(Item.language, state.opt["default-locale"][0]);
var sort_locales = state[state.tmp.area.slice(0,-5)].opt.sort_locales;
var langForItem;
for (var i=0,ilen=sort_locales.length;i<ilen;i+=1) {
langForItem = sort_locales[i][langspec.bare];
if (!langForItem) {
langForItem = sort_locales[i][langspec.best];
}
if (langForItem) {
break;
}
}
if (!langForItem) {
langForItem = state.opt["default-locale"][0];
}
state.tmp.lang_sort_hold = state.opt.lang;
state.opt.lang = langForItem;
}
} }
this.execs.push(func); this.execs.push(func);
} }
if (this.tokentype === CSL.END) { if (this.tokentype === CSL.END) {
state.build.area = state.build.root; state.build.area = state.build.root;
state.build.extension = ""; state.build.extension = "";
var func = function (state, Item) {
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); target.push(this);
} }
@ -9430,14 +9486,35 @@ CSL.Attributes["@is-plural"] = function (state, arg) {
}; };
CSL.Attributes["@locale"] = function (state, arg) { CSL.Attributes["@locale"] = function (state, arg) {
var func, ret, len, pos, variable, myitem, langspec, lang, lst, i, ilen, fallback; var func, ret, len, pos, variable, myitem, langspec, lang, lst, i, ilen, fallback;
var locale_default = state.opt["default-locale"][0];
if (this.name === "layout") { if (this.name === "layout") {
this.locale_raw = arg; this.locale_raw = arg;
if (this.tokentype === CSL.START) {
var locales = arg.split(/\s+/);
var sort_locale = {};
var localeMaster = CSL.localeResolve(locales[0], locale_default);
if (localeMaster.generic) {
sort_locale[localeMaster.generic] = localeMaster.best;
} else {
sort_locale[localeMaster.best] = localeMaster.best;
}
for (var i=1,ilen=locales.length;i<ilen;i+=1) {
var localeServant = CSL.localeResolve(locales[i], locale_default);
if (localeServant.generic) {
sort_locale[localeServant.generic] = localeMaster.best;
} else {
sort_locale[localeServant.best] = localeMaster.best;
}
}
state[state.build.area].opt.sort_locales.push(sort_locale);
}
state.opt.has_layout_locale = true;
} else { } else {
lst = arg.split(/\s+/); lst = arg.split(/\s+/);
var locale_bares = []; var locale_bares = [];
for (i = 0, ilen = lst.length; i < ilen; i += 1) { for (i = 0, ilen = lst.length; i < ilen; i += 1) {
lang = lst[i]; lang = lst[i];
langspec = CSL.localeResolve(lang); langspec = CSL.localeResolve(lang, locale_default);
if (lst[i].length === 2) { if (lst[i].length === 2) {
locale_bares.push(langspec.bare); locale_bares.push(langspec.bare);
} }
@ -9445,7 +9522,6 @@ CSL.Attributes["@locale"] = function (state, arg) {
lst[i] = langspec; lst[i] = langspec;
} }
var locale_list = lst.slice(); var locale_list = lst.slice();
var locale_default = state.opt["default-locale"][0];
var maketest = function (locale_list, locale_default,locale_bares) { var maketest = function (locale_list, locale_default,locale_bares) {
return function (Item, item) { return function (Item, item) {
var key, res; var key, res;
@ -9458,7 +9534,7 @@ CSL.Attributes["@locale"] = function (state, arg) {
} else { } else {
lang = Item.language; lang = Item.language;
} }
langspec = CSL.localeResolve(lang); langspec = CSL.localeResolve(lang, locale_default);
for (i = 0, ilen = locale_list.length; i < ilen; i += 1) { for (i = 0, ilen = locale_list.length; i < ilen; i += 1) {
if (langspec.best === locale_list[i].best) { if (langspec.best === locale_list[i].best) {
res = true; res = true;
@ -9480,7 +9556,7 @@ CSL.Attributes["@locale-internal"] = function (state, arg) {
this.locale_bares = []; this.locale_bares = [];
for (i = 0, ilen = lst.length; i < ilen; i += 1) { for (i = 0, ilen = lst.length; i < ilen; i += 1) {
lang = lst[i]; lang = lst[i];
langspec = CSL.localeResolve(lang); langspec = CSL.localeResolve(lang, state.opt["default-locale"][0]);
if (lst[i].length === 2) { if (lst[i].length === 2) {
this.locale_bares.push(langspec.bare); this.locale_bares.push(langspec.bare);
} }
@ -9498,7 +9574,7 @@ CSL.Attributes["@locale-internal"] = function (state, arg) {
var langspec = false; var langspec = false;
if (Item.language) { if (Item.language) {
lang = Item.language; lang = Item.language;
langspec = CSL.localeResolve(lang); langspec = CSL.localeResolve(lang, state.opt["default-locale"][0]);
if (langspec.best === state.opt["default-locale"][0]) { if (langspec.best === state.opt["default-locale"][0]) {
langspec = false; langspec = false;
} }
@ -9614,8 +9690,8 @@ CSL.Attributes["@match"] = function (state, arg) {
}; };
CSL.Attributes["@names-min"] = function (state, arg) { CSL.Attributes["@names-min"] = function (state, arg) {
var val = parseInt(arg, 10); var val = parseInt(arg, 10);
if (state.opt.max_number_of_names < val) { if (state[state.tmp.area].opt.max_number_of_names < val) {
state.opt.max_number_of_names = val; state[state.tmp.area].opt.max_number_of_names = val;
} }
this.strings["et-al-min"] = val; this.strings["et-al-min"] = val;
}; };
@ -9717,8 +9793,8 @@ CSL.Attributes["@name-delimiter"] = function (state, arg) {
}; };
CSL.Attributes["@et-al-min"] = function (state, arg) { CSL.Attributes["@et-al-min"] = function (state, arg) {
var val = parseInt(arg, 10); var val = parseInt(arg, 10);
if (state.opt.max_number_of_names < val) { if (state[state.tmp.area].opt.max_number_of_names < val) {
state.opt.max_number_of_names = val; state[state.tmp.area].opt.max_number_of_names = val;
} }
state.setOpt(this, "et-al-min", val); state.setOpt(this, "et-al-min", val);
}; };
@ -9734,8 +9810,8 @@ CSL.Attributes["@et-al-use-last"] = function (state, arg) {
}; };
CSL.Attributes["@et-al-subsequent-min"] = function (state, arg) { CSL.Attributes["@et-al-subsequent-min"] = function (state, arg) {
var val = parseInt(arg, 10); var val = parseInt(arg, 10);
if (state.opt.max_number_of_names < val) { if (state[state.tmp.area].opt.max_number_of_names < val) {
state.opt.max_number_of_names = val; state[state.tmp.area].opt.max_number_of_names = val;
} }
state.setOpt(this, "et-al-subsequent-min", val); state.setOpt(this, "et-al-subsequent-min", val);
}; };