closes #1779: Some CSLs can only be parsed once

Restore global XML properties when Zotero.Cite.makeFormattedBibliography() is complete. At some point, we should probably modify our existing uses of E4X not to rely on these properties being set to their defaults.
This commit is contained in:
Simon Kornblith 2011-02-02 22:18:34 +00:00
parent 0a4fe5725e
commit ddcdfb6961

View File

@ -286,79 +286,84 @@ Zotero.Cite.makeFormattedBibliography = function(cslEngine, format) {
if(entrySpacing == NaN) throw "Invalid entryspacing"; if(entrySpacing == NaN) throw "Invalid entryspacing";
if(lineSpacing == NaN) throw "Invalid linespacing"; if(lineSpacing == NaN) throw "Invalid linespacing";
default xml namespace = ''; default xml namespace = ''; with({});
XML.prettyPrinting = false; try {
XML.ignoreWhitespace = false; XML.prettyPrinting = false;
var xml = new XML(html); XML.ignoreWhitespace = false;
var xml = new XML(html);
var multiField = !!xml..div.(@class == "csl-left-margin").length(); var multiField = !!xml..div.(@class == "csl-left-margin").length();
// One of the characters is usually a period, so we can adjust this down a bit // One of the characters is usually a period, so we can adjust this down a bit
maxOffset = Math.max(1, maxOffset - 2); maxOffset = Math.max(1, maxOffset - 2);
// Force a minimum line height // Force a minimum line height
if(lineSpacing <= 1.35) lineSpacing = 1.35; if(lineSpacing <= 1.35) lineSpacing = 1.35;
xml.@style += "line-height: " + lineSpacing + "; "; xml.@style += "line-height: " + lineSpacing + "; ";
if(hangingIndent) { if(hangingIndent) {
if (multiField && !secondFieldAlign) { if (multiField && !secondFieldAlign) {
throw ("second-field-align=false and hangingindent=true combination is not currently supported"); throw ("second-field-align=false and hangingindent=true combination is not currently supported");
} }
// If only one field, apply hanging indent on root // If only one field, apply hanging indent on root
else if (!multiField) { else if (!multiField) {
xml.@style += "padding-left: " + hangingIndent + "em; text-indent:-" + hangingIndent + "em;"; xml.@style += "padding-left: " + hangingIndent + "em; text-indent:-" + hangingIndent + "em;";
}
}
// csl-entry
var divs = xml..div.(@class == "csl-entry");
var num = divs.length();
var i = 0;
for each(var div in divs) {
var first = i == 0;
var last = i == num - 1;
if(entrySpacing) {
if(!last) {
div.@style += "margin-bottom: " + entrySpacing + "em;";
} }
} }
i++; // csl-entry
} var divs = xml..div.(@class == "csl-entry");
var num = divs.length();
var i = 0;
for each(var div in divs) {
var first = i == 0;
var last = i == num - 1;
// Padding on the label column, which we need to include when if(entrySpacing) {
// calculating offset of right column if(!last) {
var rightPadding = .5; div.@style += "margin-bottom: " + entrySpacing + "em;";
}
}
// div.csl-left-margin i++;
for each(var div in xml..div.(@class == "csl-left-margin")) {
div.@style = "float: left; padding-right: " + rightPadding + "em;";
// Right-align the labels if aligning second line, since it looks
// better and we don't need the second line of text to align with
// the left edge of the label
if (secondFieldAlign) {
div.@style += "text-align: right; width: " + maxOffset + "em;";
} }
}
// div.csl-right-inline // Padding on the label column, which we need to include when
for each(var div in xml..div.(@class == "csl-right-inline")) { // calculating offset of right column
div.@style = "margin: 0 .4em 0 " + (secondFieldAlign ? maxOffset + rightPadding : "0") + "em;"; var rightPadding = .5;
if (hangingIndent) { // div.csl-left-margin
div.@style += "padding-left: " + hangingIndent + "em; text-indent:-" + hangingIndent + "em;"; for each(var div in xml..div.(@class == "csl-left-margin")) {
div.@style = "float: left; padding-right: " + rightPadding + "em;";
// Right-align the labels if aligning second line, since it looks
// better and we don't need the second line of text to align with
// the left edge of the label
if (secondFieldAlign) {
div.@style += "text-align: right; width: " + maxOffset + "em;";
}
} }
}
// div.csl-indent // div.csl-right-inline
for each(var div in xml..div.(@class == "csl-indent")) { for each(var div in xml..div.(@class == "csl-right-inline")) {
div.@style = "margin: .5em 0 0 2em; padding: 0 0 .2em .5em; border-left: 5px solid #ccc;"; div.@style = "margin: 0 .4em 0 " + (secondFieldAlign ? maxOffset + rightPadding : "0") + "em;";
}
//Zotero.debug(xml); if (hangingIndent) {
div.@style += "padding-left: " + hangingIndent + "em; text-indent:-" + hangingIndent + "em;";
}
}
// div.csl-indent
for each(var div in xml..div.(@class == "csl-indent")) {
div.@style = "margin: .5em 0 0 2em; padding: 0 0 .2em .5em; border-left: 5px solid #ccc;";
}
//Zotero.debug(xml);
} finally {
XML.prettyPrinting = true;
XML.ignoreWhitespace = true;
}
return xml.toXMLString(); return xml.toXMLString();
} else if(format == "text") { } else if(format == "text") {