diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 76d3474f7d..dac7c6386c 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -295,7 +295,7 @@ Zotero.Cite.makeFormattedBibliography = function(cslEngine, format) { var str; try { var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + .createInstance(Components.interfaces.nsIDOMParser), doc = parser.parseFromString(html, "application/xml"); var leftMarginDivs = Zotero.Utilities.xpath(doc, '//div[@class="csl-left-margin"]'), diff --git a/chrome/content/zotero/xpcom/enstyle.js b/chrome/content/zotero/xpcom/enstyle.js deleted file mode 100644 index a430ce47b1..0000000000 --- a/chrome/content/zotero/xpcom/enstyle.js +++ /dev/null @@ -1,1383 +0,0 @@ -/* - ***** BEGIN LICENSE BLOCK ***** - - Copyright © 2009 Center for History and New Media - George Mason University, Fairfax, Virginia, USA - http://zotero.org - - This file is part of Zotero. - - Zotero is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Zotero 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 a copy of the GNU Affero General Public License - along with Zotero. If not, see . - - ***** END LICENSE BLOCK ***** -*/ - -/** - * Constructor for EN converter - * @constructor - **/ -Zotero.ENConverter = function(styleData, date, fileTitle) { - this.data = styleData; - if(date) this.date = date; - if(fileTitle) this.fileTitle = fileTitle; - - var formatCode = this.data.substr(8, 8); - if(formatCode != "RSFTSTYL" && formatCode != "ENDNENFT") { - throw "Zotero.ENConverter: File not recognized. Is this a style file?"; - } -} - -// The URI prefix for EN styles -Zotero.ENConverter.uriPrefix = "http://zotero.org/styles/en-converted/"; - -/** - * Mappings for item types - * - * Those in lower case are not in the mapping list because they are implemented - * elsewhere in the code. - * Those in upper case are not implemented. - **/ -Zotero.ENConverter.typeMappings = { - "\x00":"article-journal", - "\x01":"book", - "\x02":"thesis", -// \x03 - CONFERENCE PROCEEDINGS - "\x04":"personal_communication", - "\x05":"article-newspaper", -// \x06 - PROGRAM - "\x07":"chapter", - "\x08":"article-magazine", -// \x09 - Edited Book - "\x0A":"report", - "\x0B":"map", -// \x0C - AUDIOVISUAL MATERIAL - "\x0D":"graphic", -// \x0E - UNUSED 1 - "\x0F":"patent", - "\x10":"webpage", - "\x11":"bill", - "\x12":"legal_case", -// \x13 - HEARING - "\x14":"manuscript", - "\x15":"motion_picture", -// \x16 - STATUTE -// \x17 - UNUSED 2 -// \x18 - UNUSED 3 - "\x19":"figure", -// \x1A - CHART OR TABLE -// \x1B - EQUATION -// \x1C - Electronic Article -// \x1D - Electronic Book -// \x1E - ONLINE DATABASE -// \x1F - Generic -// \x20 - GOVERNMENT DOCUMENT - "\x21":"paper-conference", -// \x22 - ONLINE MULTIMEDIA -// \x23 - CLASSICAL WORK - "\x24":"legislation", -// \x25 - UNPUBLISHED WORK -// \x26 - ANCIENT TEXT - "\x27":"entry-dictionary", - "\x28":"entry-encyclopedia" -// \x29 - GRANT -}; - -/** - * List of CSL fallback types - **/ -Zotero.ENConverter.fallbackTypes = { - "book":true, - "chapter":true, - "article":true -} - -/** - * List of types that we should parse, but not map directly - **/ -Zotero.ENConverter.supplementalTypes = { - "\x09":true, // Edited Book (use conditional on book) - "\x1C":true, // Electronic Article (use conditional on article) - "\x1D":true, // Electronic Book (use conditional on book) - "\x1F":true // Generic (use for all unspecified types) -}; - -/** - * Mappings for text variables - * - * Those in lower case are not in the mapping list because they are implemented - * elsewhere in the code. - * Those in upper case are not implemented. - **/ -Zotero.ENConverter.variableMappings = { -// \x01 - TYPE OF REFERENCE -// \x02 - Author/Editor -// \x03 - Year - "\x05":"page", -// \x06 - Secondary/Series/Publication Title/Bill Code - "\x07":"volume", - "\x08":"issue", - "\x09":"number-of-volumes", -// \x0A - Secondary/Series Author - "\x0B":"publisher-place", - "\x0C":"publisher", -// \x0D - Translator/Subsidiary Author -// \x0F - KEYWORD - "\x10":"genre", -// \x11 - Date - "\x12":"abstract", - "\x13":"citation-label", - "\x14":"URL", -// \x15 - TERTIARY TITLE -// \x16 - TERTIARY AUTHOR - "\x17":"note", - "\x18":"ISBN", -// \x19 - CUSTOM 1 -// \x1A - CUSTOM 2 -// \x1B - CUSTOM 3 -// \x1C - CUSTOM 4 -// \x1D - ABBREVIATION -// \x1E - ACCESSION NUMBER -// \x1F - CALL NUMBER -// \x21 - CUSTOM 5 -// \x22 - CUSTOM 6 -// \x23 - SECTION/PAGES CITED/Chapter Title -// \x24 - ORIGINAL PUBLICATION -// \x25 - REPRINT EDITION -// \x26 - REVIEWED ITEM -// \x27 - AUTHOR ADDRESS -// \x28 - IMAGE -// \x29 - CAPTION -// \x2A - CUSTOM 7 -// \x2B - ELECTRONIC RESOURCE NUMBER -// \x2C - LINK TO PDF -// \x2D - TRANSLATED AUTHOR -// \x2E - TRANSLATED TITLE -// \x2F - NAME OF DATABASE -// \x30 - DATABASE PROVIDER -// \x31 - RESEARCH NOTES -// \x32 - LANGUAGE -// \x33 - accessed -// \x34 - LAST MODIFIED -// \x00\x40 - citation - "\x01\x40":"citation-number", -// \x02\x40 - RECORD NUMBER - "\x06\x40":"locator" -} - -/** - * List of types that we should map to macros. - **/ -Zotero.ENConverter.macroVariables = { - "\x02":["author-citation", "author-bibliography"], // Author - "\x03":["year-citation", "year-bibliography"], // Year - "\x04":["title-citation", "title-bibliography"], // Title/Book Title - "\x06":"secondary_title", // Series/Publication Title - "\x0A":["secondary_author-citation", "secondary_author-bibliography"], // Editor/Series Editor - "\x0D":["translator-citation", "translator-bibliography"], // Translator - "\x0E":"edition", // Edition - "\x11":"date", // Date - "\x15":"tertiary_title", - "\x16":["tertiary_author-citation", "tertiary_author-bibliography"], // Chapter Series Editor - "\x20":"short-title", // Short Title/Short Book Title - "\x23":"chapter_title", // Chapter Title - "\x33":"accessed", - "\x00\x40":"citation" // Citation -}; - -/** - * List of types where \x06 maps to collection-title (rather than - * container-title) - **/ -Zotero.ENConverter.seriesTypes = "book report map motion_picture"; -Zotero.ENConverter.seriesCodes = ["\x01", "\x09", "\x0A", "\x0B", "\x15", "\x1D"]; - -/** - * Generates the element for the style - **/ -Zotero.ENConverter.prototype.parseInfo = function() { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - if(this.fileTitle) { - var title = this.fileTitle; - } else { - var title = this.convertFromUTF16(this.findField(this.fields, "\x10")[0].data.replace("\xFB", "", "g")); - } - if(!title) { - var title = "Untitled Style"; - var identifier = ""; - for(var i=0; i<16; i++) { - var bite = Math.floor(Math.random() * 255); - - if(i == 4 || i == 6 || i == 8 || i == 10) { - identifier += "-"; - - // version - if(i == 6) bite = bite & 0x0f | 0x40; - // variant - if(i == 8) bite = bite & 0x3f | 0x80; - } - var str = bite.toString(16); - identifier += str.length == 1 ? '0' + str : str; - } - } else { - var identifier = encodeURIComponent(title); - } - - this.xml.info.title = title; - this.xml.info.id = Zotero.ENConverter.uriPrefix+identifier; - - if(this.date) { - var date = this.date; - } else { - var date = new Date(); - } - - var y = date.getFullYear().toString(); - var m = (date.getUTCMonth()+1).toString(); - var d = date.getUTCDay().toString(); - var h = date.getUTCHours().toString(); - var n = date.getUTCMinutes().toString(); - var s = date.getUTCSeconds().toString(); - if(m.length == 1) m = "0"+m; - if(d.length == 1) d = "0"+d; - if(h.length == 1) h = "0"+h; - if(n.length == 1) n = "0"+n; - if(s.length == 1) s = "0"+s; - this.xml.info.updated = y+"-"+m+"-"+d+"T"+h+":"+n+":"+s+"+00:00"; -} - -/** - * Converts a little endian binary representation of an integer into a JS integer - * - * @param {String} binaryData The binary representation of the integer - * @returns The JS integer - * @type Integer - **/ -Zotero.ENConverter.prototype.parseInt = function(binaryData) { - if(binaryData.length == 4) { - // since this is so common, avoid overhead - return binaryData.charCodeAt(0)+binaryData.charCodeAt(1)*0x100 - +binaryData.charCodeAt(2)*0x10000+binaryData.charCodeAt(3)*0x1000000; - } else { - var integer = 0; - for(var i=0; i tags instead of - * plain text - * - * @returns Plain text, or the XML representation as tags, depending on - * the richOutput parameter - **/ -Zotero.ENConverter.prototype.parseFormattedString = function(string, richOutput) { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - var stringLength = this.parseInt(string.substr(4, 4))-8; - if(stringLength == 0) return richOutput ? false : ""; - - var newString = this.convertFromUTF16(string.substr(8, stringLength)); - - // strip out chars that shouldn't be there - newString = newString.replace(/[\x00-\x08\x0E-\x1F]/g, ""); - - if(richOutput) { - var formattedXML = new XML(); - var lastOffset = 0; - var style = false; - - var i = stringLength + 8; - while(i < string.length) { - var length = this.parseInt(string.substr(i+4, 4)); - var data = string.substr(i+8, length-8); - if(length == 0) break; - var startOffset = this.parseInt(data.substr(4, 4)); - - // add term containing text from last element to new element - var text = newString.substring(lastOffset, startOffset); - if(lastOffset != startOffset) { - var textElement = ; - if(style) this.applyFormattingAttributes(textElement, style); - formattedXML += textElement; - } - - var style = data.substr(data.indexOf("&")+4, 4); - lastOffset = startOffset; - - i += length + length % 4; - } - - if(lastOffset != newString.length) { - var text = newString.substring(lastOffset); - var textElement = ; - if(style) this.applyFormattingAttributes(textElement, style); - formattedXML += textElement; - } - - return formattedXML; - } else { - return newString; - } -} - - -/** - * Applies the formatting attributes specified by a binary string to a given - * text element - * - * @param {XML} element The element to which the formatting attributes will be - * applied - * @param {String} formatCode The binary format string - **/ -Zotero.ENConverter.prototype.applyFormattingAttributes = function(element, formatCode) { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - if(!formatCode) return; - - var binaryDigits = this.parseInt(formatCode).toString(2); - // pad to 7 digits - while(binaryDigits.length < 7) binaryDigits = "0"+binaryDigits; - - if(binaryDigits[6] == "1") { // italics - element["@font-weight"] = "bold"; - } - if(binaryDigits[5] == "1") { // bold - element["@font-style"] = "italic"; - } - if(binaryDigits[4] == "1") { // underline - element["@text-decoration"] = "underline"; - } - // what are bits 3 and 2? - if(binaryDigits[1] == "1") { // subscript - element["@vertical-align"] = "sup"; - } else if(binaryDigits[0] == "1") { // superscript - element["@vertical-align"] = "sub"; - } -} - -/** - * Parses format to create a hierarchical data structure - * - * @param {String} styleData The EN style file, as binary data - * @returns An array of objects representing the structure of the EN file - * @type Array - **/ -Zotero.ENConverter.prototype.parseFormat = function(styleData) { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - var fields = []; - - var offset1 = styleData.indexOf("\x10"); - var offset2 = styleData.indexOf("\x11"); - if(offset1 != -1 && (offset2 == -1 || offset1 < offset2)) { // \x10 comes first - var offset = offset1; - } else if(offset2 != -1) { // \x11 comes first - var offset = offset2; - } else { // both must be -1; no tags here - return [styleData.replace("\xFB", "", "g")]; - } - // want to start with tag before - offset--; - // for the \x10\x10 case - if(offset === -1) offset = 0; - - if(offset !== 0) { - fields.push(styleData.substr(0, offset).replace("\xFB", "", "g")); - } - - while(offset < styleData.length) { - if((styleData[offset] == "\x10" || styleData[offset] == "\x11" || styleData[offset] == "\x12") - && styleData[offset+1] == "\x00" && styleData[offset+2] == "\x03") { - // 10 00 02 style short tag (use unknown) - - fields.push({dle:styleData[offset], - type:"\x00", - flags:styleData[offset+3], - data:styleData.substr(offset+4, 4)}); - - offset += 8; - } else if(styleData[offset+2] == "\x01" || styleData[offset+2] == "\x02") { - // standard data-bearing tag - - // size is little endian - var size = this.parseInt(styleData.substr(offset+4, 4)); - size += size % 4; - - // set field data - var field = {code:styleData[offset], - dle:styleData[offset+1], - type:styleData[offset+2], - flags:styleData[offset+3], - size:size, - data:styleData.substr(offset+8, size-8)}; - field.subfields = this.parseFormat(field.data); - fields.push(field); - - offset += size; - } else if(styleData[offset+2] == "\x03" || styleData[offset+2] == "\x00") { - // 10 03 style short tag (use unknown) - - fields.push({code:styleData[offset], - dle:styleData[offset+1], - type:"\x03", - flags:styleData[offset+3], - data:styleData.substr(offset+4, 4)}); - - offset += 8; - } else if(styleData[offset+1] != "\x10" && styleData[offset+1] != "\x11") { - // unknown tag; error out - throw("Zotero.ENConverter: Unexpected end of file at "+offset.toString(16)+"; "+varDump(styleData.substr(offset, offset+4))); - } - } - - return fields; -} - -/** - * Finds all instances of a given field at a given level of the hierarchy - * @param {Array} fields The array of fields - * @param {String} code The field code - **/ -Zotero.ENConverter.prototype.findField = function(fields, code) { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - var output = []; - - while(code.length) { - if(typeof code != "object") { - var searchCode = code; - code = []; - } else { - var searchCode = code.shift(); - } - - for(var i=0; i tag - * - * @param {Object} options A binary field object - * @returns A tag - * @type XML - **/ -Zotero.ENConverter.prototype.parseName = function(options) { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - var authorXML = ; - - // "Author Lists" preferences - var delimiterOptions = this.findField(options.subfields, ["t", "x"]); - if(this.parseInt(this.findField(delimiterOptions[0].subfields, ["z"])[0].data) == 2) { - // this probably means delimiter-precedes-last shouldn't be set, because - // this is probably configured such that, from 1-2, we use no delimiter - // before the last, but for all other numbers of authors we do - var delimiter = this.parseFormattedString(this.findField(delimiterOptions[1].subfields, "{")[0].data); - var lastDelimiter = this.parseFormattedString(this.findField(delimiterOptions[1].subfields, "|")[0].data); - } else { - var delimiter = this.parseFormattedString(this.findField(delimiterOptions[0].subfields, "{")[0].data); - var lastDelimiter = this.parseFormattedString(this.findField(delimiterOptions[0].subfields, "|")[0].data); - // delimiter-precedes-last should probably be "always" or "never" - // ignore second set of list separator options - if(lastDelimiter.length >= delimiter.length - && lastDelimiter.substr(0, delimiter.length) == delimiter) { - // there is a delimiter preceding the last - authorXML["@delimiter-precedes-last"] = "always"; - } else { - // there is no delimiter - authorXML["@delimiter-precedes-last"] = "never"; - } - } - if(delimiter !== "") authorXML["@delimiter"] = delimiter; - // TODO: alter locale "and" if neither text nor symbol - if(lastDelimiter.indexOf("and") !== -1) { - // text and - authorXML["@and"] = "text"; - } else if(lastDelimiter.indexOf("&") !== -1) { - // symbol and - authorXML["@and"] = "symbol"; - } - - // "Author Name" preferences - var firstAuthorPref = this.findField(options.subfields, "q")[0].data[0]; - var subsequentAuthorPref = this.findField(options.subfields, "r")[0].data[0]; - if(firstAuthorPref != "\x00") { - if(subsequentAuthorPref != "\x00") { - authorXML["@name-as-sort-order"] = "all"; - } else { - authorXML["@name-as-sort-order"] = "first"; - } - } - if(firstAuthorPref == "\x01") { - authorXML["@sort-separator"] = ", "; - } else if(firstAuthorPref == "\x02") { - authorXML["@sort-separator"] = " "; - } - - var capitalizationPref = this.findField(options.subfields, "s")[0].data[0]; - if(capitalizationPref == "\x02") { - authorXML["@text-case"] = "uppercase"; - } else if(capitalizationPref == "\x03") { - authorXML["@font-variant"] = "small-caps"; - } - - var initialPref = this.findField(options.subfields, "p")[0].data[0]; - if(initialPref == "\x01") { // B. C. - authorXML["@initialize-with"] = ". "; - } else if(initialPref == "\x02") { // B.C. - authorXML["@initialize-with"] = "."; - } else if(initialPref == "\x03") { // B C - authorXML["@initialize-with"] = " "; - } else if(initialPref == "\x04") { // BC - authorXML["@initialize-with"] = ""; - } else if(initialPref == "\x05") { // just last name - authorXML["@form"] = "short"; - } - - return authorXML; -} - -/** - * Parses options pertaining to subsequent author handling - * - * @param {Object} etAlOptions A binary field object - * @param {XML} context The CSL context ( or tag) - * @param {Boolean} subsequent Whether this set of fields controls the behavior - * of subsequent references. - **/ -Zotero.ENConverter.prototype.parseEtAl = function(etAlOptions, context, subsequent) { - default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); - - if(this.findField(etAlOptions.subfields, "}")[0].data[0] == "\x01") { - // if author list abbreviation is on - - // et-al-min - var value = this.parseInt(this.findField(etAlOptions.subfields, "~")[0].data); - var optionName = subsequent ? "et-al-subsequent-min" : "et-al-min"; - context.prependChild(