Ticket #1262: zs15_fbennett_2008-12-17.patch
| File zs15_fbennett_2008-12-17.patch, 7.5 KB (added by fbennett, 8 years ago) |
|---|
-
content/zotero/xpcom/csl.js
diff -r -u chrome.orig/content/zotero/xpcom/csl.js chrome/content/zotero/xpcom/csl.js
old new 21 21 */ 22 22 23 23 /* 24 * PATCHES: fbennett 25 * 26 * This version of cls.js reflects the following four modifications: 27 * 28 * (1) Fix bug in handling of label pluralizations with et al.: 29 * Currently, the pluralization of labels used with names is 30 * determined by the number of names in the formatted string. 31 * For styles that call for showing only one name with et al., 32 * this causes a singular label to be used in this case 33 * (i.e. "John Doe et al. ed." rather than "John Doe et al. eds."). 34 * 35 * The fbennett (1) change below addresses this issue. 36 * 37 * (2) Make the is-numeric test available with note/extra and locator 38 * fields: 39 * The Extra field can be used to overcome limitations in a 40 * style, for use cases the are not covered by the current schema 41 * (such as the handling of an original and a modern publication 42 * date for a resource). The locator field is likely to come 43 * under pressure for special pinpoint forms of a citation in 44 * footnote styles. 45 * 46 * The changes labeled fbennett (2) below improve the utility of 47 * these fields by extending the is-numeric expression to cover 48 * them. 49 * 50 * (3) New is-phrase test: 51 * This test returns true if there is a space character in the 52 * target field (i.e. if it contains more than one word). This 53 * opens a path for the exceptional handling of fields which 54 * normally contain a single word or number, and take (the edition field is 55 * the obvious example). This will be needed for hands-free 56 * processing of the Bluebook style. 57 * 58 * The changes labled fbennett (3) below provide this test. 59 * 60 * (4) New lastchar-num test: 61 * In the Bluebook style, the separator between a book title and 62 * a page number changes from " " to ", at " where the title ends 63 * in a number (and the division between title and page number is 64 * therefore unclear). This test makes it possible to cope with 65 * this case, at the cost of three lines of new code in csl.js. 66 * 67 * The changes labeled fbennett (4) below provide this test. 68 */ 69 70 /* 24 71 * CSL: a class for creating bibliographies from CSL files 25 72 * this is abstracted as a separate class for the benefit of anyone who doesn't 26 73 * want to use the Scholar data model, but does want to use CSL in JavaScript … … 99 146 Zotero.CSL._firstNameRegexp = /^[^\s]*/; 100 147 Zotero.CSL._textCharRegexp = /[a-zA-Z0-9]/; 101 148 Zotero.CSL._numberRegexp = /\d+/; 149 /* 150 * fbennett (3): adding regexp for detecting spaces in string 151 */ 152 Zotero.CSL._spaceRegexp = /\s/; 153 /* 154 * fbennett: end 155 */ 156 /* fbennett (4): adding regexp for detecting digit as last character in 157 * field 158 */ 159 Zotero.CSL._lastcharnumRegexp = /[0-9]$/; 160 /* 161 * fbennett: end 162 */ 102 163 Zotero.CSL.prototype.formatCitation = function(citation, format) { 103 164 default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); 104 165 … … 694 755 } 695 756 } else if(formattedString.format != "Sort" && 696 757 name == "label" && variables[j] != "author") { 697 newString.append(this._getTerm(variables[j], (maxCreators != 1), child["@form"].toString(), child["@include-period"] == "true"), child); 758 /* 759 * fbennett (1): Force names with et al. to plural 760 */ 761 newString.append(this._getTerm(variables[j], (maxCreators != 1 || useEtAl), child["@form"].toString(), child["@include-period"] == "true"), child); 762 /* 763 * fbennett: end 764 */ 698 765 } 699 766 } 700 767 success = true; … … 803 870 for(var j=0; j<variables.length; j++) { 804 871 if(ignore[0][variables[j]]) continue; 805 872 806 var text = item.getNumericVariable(variables[j], form); 873 /* 874 * fbennett (2): pass citationItem through to provide locator field data to function 875 */ 876 var text = item.getNumericVariable(variables[j], citationItem, form); 877 /* 878 * fbennett: end 879 */ 807 880 if(text) { 808 881 newString.append(text); 809 882 success = true; … … 1036 1109 1037 1110 // inspect variables 1038 1111 var done = false; 1039 var attributes = ["variable", "is-date", "is-numeric", "is-plural", "type", "disambiguate", "locator", "position"]; 1112 /* 1113 * fbennett (3) (4): add is-phrase and lastnum-char to attributes list 1114 */ 1115 var attributes = ["variable", "is-date", "is-numeric", "is-plural", "type", "disambiguate", "locator", "position", "is-phrase", "lastchar-num"]; 1116 /* 1117 * fbennett: end 1118 */ 1040 1119 for(var k=0; !done && k<attributes.length; k++) { 1041 1120 var attribute = attributes[k]; 1042 1121 … … 1061 1140 if (exists) exists = !!exists.length; 1062 1141 } 1063 1142 } else if (attribute == "is-numeric") { 1064 exists = item.getNumericVariable(variables[j]); 1143 /* 1144 * fbennett (2): pass through citationItem to provide locator field data to function 1145 */ 1146 exists = item.getNumericVariable(variables[j], citationItem); 1147 /* 1148 * fbennett: end 1149 */ 1065 1150 } else if (attribute == "is-date") { // XXX - this needs improving 1066 1151 if (Zotero.CSL._dateVariables[variables[j]]) { 1067 1152 exists = !!item.getDate(variables[j]); … … 1087 1172 exists = citationItem && citationItem.locator && 1088 1173 (citationItem.locatorType == variables[j] 1089 1174 || (!citationItem.locatorType && variables[j] == "page")); 1175 /* 1176 * fbennett (3): adding is-phrase condition 1177 */ 1178 } else if (attribute == "is-phrase") { 1179 exists = item.getVariable(variables[j]).match(Zotero.CSL._spaceRegexp); 1180 /* 1181 * fbennett: end 1182 */ 1183 /* 1184 * fbennett (4): adding lastum-char condition 1185 */ 1186 } else if (attribute == "lastchar-num") { 1187 exists = item.getVariable(variables[j]).match(Zotero.CSL._lastcharnumRegexp); 1188 /* 1189 * fbennett: end 1190 */ 1090 1191 } else { // attribute == "position" 1091 1192 if(variables[j] == "first") { 1092 1193 exists = !citationItem … … 1882 1983 "issue":"issue", 1883 1984 "number-of-volumes":"numberOfVolumes", 1884 1985 "edition":"edition", 1885 "number":"number" 1986 /* 1987 * fbennett (2): adding note and locator fields to number field map 1988 */ 1989 "number":"number", 1990 "note":"extra", 1991 "locator":"locator" 1992 /* 1993 * fbennett: end 1994 */ 1886 1995 } 1887 1996 /* 1888 1997 * Gets a numeric object for a specific type. <number variable="edition" form="roman"/> 1889 1998 */ 1890 Zotero.CSL.Item.prototype.getNumericVariable = function(variable, form) { 1891 1999 /* 2000 * fbennett (2): adding citationItem argument to function to gain access to locator field data 2001 */ 2002 Zotero.CSL.Item.prototype.getNumericVariable = function(variable, citationItem, form) { 2003 /* 2004 * fbennett: end 2005 */ 1892 2006 if(!Zotero.CSL.Item._zoteroNumberFieldMap[variable]) return ""; 1893 2007 1894 2008 var zoteroFields = []; … … 1903 2017 1904 2018 var matches; 1905 2019 for each(var zoteroField in zoteroFields) { 1906 var value = this.zoteroItem.getField(zoteroField, false, true); 2020 /* 2021 * fbennett (2): adding special handling for locator field 2022 */ 2023 if(zoteroField == "locator") { 2024 var value = citationItem.locator; 2025 } else { 2026 var value = this.zoteroItem.getField(zoteroField, false, true); 2027 } 2028 /* 2029 * fbennett: end 2030 */ 1907 2031 var matches; 1908 2032 if(value != "" && (matches = value.toString().match(Zotero.CSL._numberRegexp)) ) { 1909 2033 value = matches[0];