update to citeproc-js 1.0.133

This commit is contained in:
Simon Kornblith 2011-03-26 21:55:46 +00:00
parent c906c8e0be
commit f2fba1b14c

View file

@ -296,19 +296,12 @@ var CSL = {
}; };
CSL.TERMINAL_PUNCTUATION_REGEXP = new RegExp("^([" + CSL.TERMINAL_PUNCTUATION.slice(0, -1).join("") + "])(.*)"); CSL.TERMINAL_PUNCTUATION_REGEXP = new RegExp("^([" + CSL.TERMINAL_PUNCTUATION.slice(0, -1).join("") + "])(.*)");
CSL.CLOSURES = new RegExp(".*[\\]\\)]"); CSL.CLOSURES = new RegExp(".*[\\]\\)]");
if ("object" === typeof console && "function" === typeof console.log) { CSL.debug = function (str) {
CSL.debug = function (str) { Zotero.debug("CSL: " + str);
console.log("CSL: " + str); };
}; CSL.error = function (str) {
CSL.error = function (str) { Zotero.debug("CSL error: " + str);
console.log("CSL error: " + str); };
};
} else {
CSL.debug = function () {};
CSL.error = function (str) {
throw "CSL error: " + str;
};
}
var CSL_E4X = function () {}; var CSL_E4X = function () {};
CSL_E4X.prototype.clean = function (xml) { CSL_E4X.prototype.clean = function (xml) {
xml = xml.replace(/<\?[^?]+\?>/g, ""); xml = xml.replace(/<\?[^?]+\?>/g, "");
@ -472,12 +465,6 @@ CSL_E4X.prototype.addInstitutionNodes = function(myxml) {
} }
} }
}; };
CSL.error = function (str) {
Zotero.log("CSL: " + str, "error");
};
CSL.debug = function (str) {
Zotero.debug("CSL: " + str);
};
CSL.Output = {}; CSL.Output = {};
CSL.Output.Queue = function (state) { CSL.Output.Queue = function (state) {
this.levelname = ["top"]; this.levelname = ["top"];
@ -1752,7 +1739,7 @@ CSL.DateParser = function (txt) {
}; };
CSL.Engine = function (sys, style, lang, forceLang) { CSL.Engine = function (sys, style, lang, forceLang) {
var attrs, langspec, localexml, locale; var attrs, langspec, localexml, locale;
this.processor_version = "1.0.131"; this.processor_version = "1.0.133";
this.csl_version = "1.0"; this.csl_version = "1.0";
this.sys = sys; this.sys = sys;
this.sys.xml = new CSL.System.Xml.Parsing(); this.sys.xml = new CSL.System.Xml.Parsing();
@ -2641,7 +2628,18 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre,
this.tmp.citation_errors = []; this.tmp.citation_errors = [];
return_data = {"bibchange": false}; return_data = {"bibchange": false};
this.registry.return_data = return_data; this.registry.return_data = return_data;
if (citation) {
CSL.debug("citationID received by processCitationCluster(): ("+citation.citationID+")");
} else {
CSL.error("nil citation received by processCitationCluster()");
}
this.setCitationId(citation); this.setCitationId(citation);
if (citation) {
CSL.debug(" citationID after setCitationId(): ("+citation.citationID+")");
CSL.debug(" citationreg.citationById object for "+citation.citationID+": ("+this.registry.citationreg.citationById[citation.citationID]+")");
} else {
CSL.error(" nil citation after setCitationID()");
}
if (flag === CSL.PREVIEW) { if (flag === CSL.PREVIEW) {
var oldCitationList = this.registry.citationreg.citationByIndex.slice(); var oldCitationList = this.registry.citationreg.citationByIndex.slice();
var oldItemList = this.registry.reflist.slice(); var oldItemList = this.registry.reflist.slice();
@ -2693,6 +2691,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre,
len = citationsPre.length; len = citationsPre.length;
for (pos = 0; pos < len; pos += 1) { for (pos = 0; pos < len; pos += 1) {
c = citationsPre[pos]; c = citationsPre[pos];
CSL.debug(" -- attempting to access Pre citation with ID: ("+c[0]+")");
this.registry.citationreg.citationById[c[0]].properties.noteIndex = c[1]; this.registry.citationreg.citationById[c[0]].properties.noteIndex = c[1];
citationByIndex.push(this.registry.citationreg.citationById[c[0]]); citationByIndex.push(this.registry.citationreg.citationById[c[0]]);
} }
@ -2700,6 +2699,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre,
len = citationsPost.length; len = citationsPost.length;
for (pos = 0; pos < len; pos += 1) { for (pos = 0; pos < len; pos += 1) {
c = citationsPost[pos]; c = citationsPost[pos];
CSL.debug(" -- attempting to access Post citation with ID: ("+c[0]+")");
this.registry.citationreg.citationById[c[0]].properties.noteIndex = c[1]; this.registry.citationreg.citationById[c[0]].properties.noteIndex = c[1];
citationByIndex.push(this.registry.citationreg.citationById[c[0]]); citationByIndex.push(this.registry.citationreg.citationById[c[0]]);
} }
@ -4019,7 +4019,7 @@ CSL.Node.key = {
state.transform.init("empty", "title"); state.transform.init("empty", "title");
state.transform.setTransformLocale("locale-sort"); state.transform.setTransformLocale("locale-sort");
state.transform.setTransformFallback(true); state.transform.setTransformFallback(true);
func = state.transform.getOutputFunction(); func = state.transform.getOutputFunction(this.variables);
} else { } else {
func = function (state, Item) { func = function (state, Item) {
var varval = Item[variable]; var varval = Item[variable];
@ -5143,7 +5143,12 @@ CSL.Node.text = {
if (this.postponed_macro) { if (this.postponed_macro) {
CSL.expandMacro.call(state, this); CSL.expandMacro.call(state, this);
} else { } else {
variable = this.variables[0]; if (!this.variables_real) {
this.variables_real = [];
}
if (!this.variables) {
this.variables = [];
}
form = "long"; form = "long";
plural = 0; plural = 0;
if (this.strings.form) { if (this.strings.form) {
@ -5152,8 +5157,8 @@ CSL.Node.text = {
if (this.strings.plural) { if (this.strings.plural) {
plural = this.strings.plural; plural = this.strings.plural;
} }
if ("citation-number" === variable || "year-suffix" === variable || "citation-label" === variable) { if ("citation-number" === this.variables_real[0] || "year-suffix" === this.variables_real[0] || "citation-label" === this.variables_real[0]) {
if (variable === "citation-number") { if (this.variables_real[0] === "citation-number") {
if (state.build.area === "citation") { if (state.build.area === "citation") {
state.opt.update_mode = CSL.NUMERIC; state.opt.update_mode = CSL.NUMERIC;
} }
@ -5190,7 +5195,7 @@ CSL.Node.text = {
} }
}; };
this.execs.push(func); this.execs.push(func);
} else if (variable === "year-suffix") { } else if (this.variables_real[0] === "year-suffix") {
state.opt.has_year_suffix = true; state.opt.has_year_suffix = true;
if (state[state.tmp.area].opt.collapse === "year-suffix-ranged") { if (state[state.tmp.area].opt.collapse === "year-suffix-ranged") {
this.range_prefix = "-"; this.range_prefix = "-";
@ -5221,7 +5226,7 @@ CSL.Node.text = {
} }
}; };
this.execs.push(func); this.execs.push(func);
} else if (variable === "citation-label") { } else if (this.variables_real[0] === "citation-label") {
state.opt.has_year_suffix = true; state.opt.has_year_suffix = true;
func = function (state, Item) { func = function (state, Item) {
label = Item["citation-label"]; label = Item["citation-label"];
@ -5290,51 +5295,52 @@ CSL.Node.text = {
state.build.term = false; state.build.term = false;
state.build.form = false; state.build.form = false;
state.build.plural = false; state.build.plural = false;
} else if (this.variables.length) { } else if (this.variables_real.length) {
func = function (state, Item) { func = function (state, Item) {
state.parallel.StartVariable(this.variables[0]); state.parallel.StartVariable(this.variables[0]);
state.parallel.AppendToVariable(Item[this.variables[0]]); state.parallel.AppendToVariable(Item[this.variables[0]]);
}; };
this.execs.push(func); this.execs.push(func);
if (CSL.MULTI_FIELDS.indexOf(this.variables[0]) > -1) { if (CSL.MULTI_FIELDS.indexOf(this.variables_real[0]) > -1) {
if (form === "short") { if (form === "short") {
state.transform.init(this, this.variables[0], this.variables[0]); state.transform.init(this, this.variables_real[0], this.variables_real[0]);
} else { } else {
state.transform.init(this, this.variables[0]); state.transform.init(this, this.variables_real[0]);
} }
if (state.build.area.slice(-5) === "_sort") { if (state.build.area.slice(-5) === "_sort") {
state.transform.init(this, this.variables_real[0], this.variables_real[0]);
state.transform.setTransformLocale("locale-sort"); state.transform.setTransformLocale("locale-sort");
state.transform.setTransformFallback(true); state.transform.setTransformFallback(true);
func = state.transform.getOutputFunction(); func = state.transform.getOutputFunction(this.variables);
} else if (form === "short") { } else if (form === "short") {
if (["title", "container-title", "collection-title"].indexOf(this.variables[0]) > -1) { if (["title", "container-title", "collection-title"].indexOf(this.variables_real[0]) > -1) {
state.transform.setTransformLocale("locale-sec"); state.transform.setTransformLocale("locale-sec");
} else { } else {
state.transform.setTransformLocale("locale-pri"); state.transform.setTransformLocale("locale-pri");
} }
state.transform.setTransformFallback(true); state.transform.setTransformFallback(true);
state.transform.setAbbreviationFallback(true); state.transform.setAbbreviationFallback(true);
if (this.variables[0] === "container-title") { if (this.variables_real[0] === "container-title") {
state.transform.setAlternativeVariableName("journalAbbreviation"); state.transform.setAlternativeVariableName("journalAbbreviation");
} else if (this.variables[0] === "title") { } else if (this.variables_real[0] === "title") {
state.transform.setAlternativeVariableName("shortTitle"); state.transform.setAlternativeVariableName("shortTitle");
} else if (["publisher", "publisher-place", "edition"].indexOf(this.variables[0]) > -1) { } else if (["publisher", "publisher-place", "edition"].indexOf(this.variables_real[0]) > -1) {
state.transform.setTransformLocale("default-locale"); state.transform.setTransformLocale("default-locale");
} }
func = state.transform.getOutputFunction(); func = state.transform.getOutputFunction(this.variables);
} else if (["title", "container-title", "collection-title"].indexOf(this.variables[0]) > -1) { } else if (["title", "container-title", "collection-title"].indexOf(this.variables_real[0]) > -1) {
state.transform.setTransformLocale("locale-sec"); state.transform.setTransformLocale("locale-sec");
state.transform.setTransformFallback(true); state.transform.setTransformFallback(true);
func = state.transform.getOutputFunction(); func = state.transform.getOutputFunction(this.variables);
} else { } else {
state.transform.setTransformLocale("locale-pri"); state.transform.setTransformLocale("locale-pri");
state.transform.setTransformFallback(true); state.transform.setTransformFallback(true);
if (["publisher", "publisher-place", "edition"].indexOf(this.variables[0]) > -1) { if (["publisher", "publisher-place", "edition"].indexOf(this.variables_real[0]) > -1) {
state.transform.setTransformLocale("default-locale"); state.transform.setTransformLocale("default-locale");
} }
func = state.transform.getOutputFunction(); func = state.transform.getOutputFunction(this.variables);
} }
if (this.variables[0] === "container-title") { if (this.variables_real[0] === "container-title") {
var xfunc = function (state, Item, item) { var xfunc = function (state, Item, item) {
if (Item['container-title'] && state.tmp.citeblob.has_volume) { if (Item['container-title'] && state.tmp.citeblob.has_volume) {
state.tmp.citeblob.can_suppress_identical_year = true; state.tmp.citeblob.can_suppress_identical_year = true;
@ -5343,13 +5349,13 @@ CSL.Node.text = {
this.execs.push(xfunc); this.execs.push(xfunc);
} }
} else { } else {
if (CSL.CITE_FIELDS.indexOf(this.variables[0]) > -1) { if (CSL.CITE_FIELDS.indexOf(this.variables_real[0]) > -1) {
func = function (state, Item, item) { func = function (state, Item, item) {
if (item && item[this.variables[0]]) { if (item && item[this.variables[0]]) {
state.output.append(item[this.variables[0]], this); state.output.append(item[this.variables[0]], this);
} }
}; };
} else if (this.variables[0] === "page-first") { } else if (this.variables_real[0] === "page-first") {
func = function (state, Item) { func = function (state, Item) {
var idx, value; var idx, value;
value = state.getVariable(Item, "page", form); value = state.getVariable(Item, "page", form);
@ -5361,7 +5367,7 @@ CSL.Node.text = {
state.output.append(value, this); state.output.append(value, this);
} }
}; };
} else if (this.variables[0] === "page") { } else if (this.variables_real[0] === "page") {
func = function (state, Item) { func = function (state, Item) {
var value = state.getVariable(Item, "page", form); var value = state.getVariable(Item, "page", form);
if (value) { if (value) {
@ -5371,17 +5377,21 @@ CSL.Node.text = {
}; };
} else if ("volume") { } else if ("volume") {
func = function (state, Item) { func = function (state, Item) {
var value = state.getVariable(Item, this.variables[0], form); if (this.variables[0]) {
if (value) { var value = state.getVariable(Item, this.variables[0], form);
state.tmp.citeblob.has_volume = true; if (value) {
state.output.append(value, this); state.tmp.citeblob.has_volume = true;
state.output.append(value, this);
}
} }
}; };
} else { } else {
func = function (state, Item) { func = function (state, Item) {
var value = state.getVariable(Item, this.variables[0], form); if (this.variables[0]) {
if (value) { var value = state.getVariable(Item, this.variables[0], form);
state.output.append(value, this); if (value) {
state.output.append(value, this);
}
} }
}; };
} }
@ -5471,7 +5481,9 @@ CSL.Attributes["@variable"] = function (state, arg) {
} else if (["names", "date", "text", "number"].indexOf(this.name) > -1) { } else if (["names", "date", "text", "number"].indexOf(this.name) > -1) {
func = function (state, Item) { func = function (state, Item) {
variables = this.variables_real.slice(); variables = this.variables_real.slice();
this.variables = []; for (var i = this.variables.length - 1; i > -1; i += -1) {
this.variables.pop();
};
len = variables.length; len = variables.length;
for (pos = 0; pos < len; pos += 1) { for (pos = 0; pos < len; pos += 1) {
if (state.tmp.done_vars.indexOf(variables[pos]) === -1) { if (state.tmp.done_vars.indexOf(variables[pos]) === -1) {
@ -6269,7 +6281,7 @@ CSL.Transform = function (state) {
} }
} }
this.setAbbreviations = setAbbreviations; this.setAbbreviations = setAbbreviations;
function getOutputFunction() { function getOutputFunction(variables) {
var mytoken, mysubsection, myfieldname, abbreviation_fallback, alternative_varname, transform_locale, transform_fallback, getTextSubfield; var mytoken, mysubsection, myfieldname, abbreviation_fallback, alternative_varname, transform_locale, transform_fallback, getTextSubfield;
mytoken = CSL.Util.cloneToken(token); // the token isn't needed, is it? mytoken = CSL.Util.cloneToken(token); // the token isn't needed, is it?
mysubsection = subsection; mysubsection = subsection;
@ -6281,6 +6293,9 @@ CSL.Transform = function (state) {
if (false && mysubsection) { if (false && mysubsection) {
return function (state, Item) { return function (state, Item) {
var primary; var primary;
if (!variables[0]) {
return null;
}
primary = getTextSubField(Item, myfieldname, transform_locale, transform_fallback); primary = getTextSubField(Item, myfieldname, transform_locale, transform_fallback);
primary = abbreviate(state, Item, alternative_varname, primary, mysubsection, true); primary = abbreviate(state, Item, alternative_varname, primary, mysubsection, true);
state.output.append(primary, this); state.output.append(primary, this);
@ -6288,6 +6303,9 @@ CSL.Transform = function (state) {
} else if (transform_locale === "locale-sec") { } else if (transform_locale === "locale-sec") {
return function (state, Item) { return function (state, Item) {
var primary, secondary, primary_tok, secondary_tok, key; var primary, secondary, primary_tok, secondary_tok, key;
if (!variables[0]) {
return null;
}
if (state.opt["locale-suppress-title-transliteration"] if (state.opt["locale-suppress-title-transliteration"]
|| !((state.tmp.area === 'bibliography' || !((state.tmp.area === 'bibliography'
|| (state.opt.xclass === "note" && || (state.opt.xclass === "note" &&
@ -6321,6 +6339,9 @@ CSL.Transform = function (state) {
} else { } else {
return function (state, Item) { return function (state, Item) {
var primary; var primary;
if (!variables[0]) {
return null;
}
primary = getTextSubField(Item, myfieldname, transform_locale, transform_fallback); primary = getTextSubField(Item, myfieldname, transform_locale, transform_fallback);
state.output.append(primary, this); state.output.append(primary, this);
return null; return null;