Ticket #1262: zs15_fbennett_2008-12-18-3.patch

File zs15_fbennett_2008-12-18-3.patch, 4.3 KB (added by fbennett, 8 years ago)

Add is-quoted test for use with all fields and the user-entered locator string (updated)

  • content/zotero/xpcom/csl.js

    diff -r -u chrome.orig/content/zotero/xpcom/csl.js chrome/content/zotero/xpcom/csl.js
    old new  
    2020    ***** END LICENSE BLOCK ***** 
    2121*/ 
    2222 
     23 /* 
     24 * PATCHES: fbennett 
     25 * 
     26 * This patch incorporates the following modification: 
     27 * 
     28 * (3) New is-quoted test: 
     29 *       This test returns true if the target field is enclosed in 
     30 *     double-quote marks.  This opens a path for the exceptional  
     31 *     handling of fields which normally contain a single word or  
     32 *     number, and take (the edition field is the obvious example). 
     33 *     Some such facility will be needed for hands-free processing  
     34 *     of the Bluebook style. 
     35 * 
     36 *     The changes labled fbennett (3) below provide this test. 
     37 */ 
     38 
    2339/* 
    2440 * CSL: a class for creating bibliographies from CSL files 
    2541 * this is abstracted as a separate class for the benefit of anyone who doesn't 
     
    99115Zotero.CSL._firstNameRegexp = /^[^\s]*/; 
    100116Zotero.CSL._textCharRegexp = /[a-zA-Z0-9]/; 
    101117Zotero.CSL._numberRegexp = /\d+/; 
     118/* 
     119 * fbennett (3): adding regexp for detecting enclosing quotes 
     120 */ 
     121Zotero.CSL._quotedRegexp = /^(".*")$/; 
     122/*  
     123 * fbennett: end 
     124 */ 
    102125Zotero.CSL.prototype.formatCitation = function(citation, format) { 
    103126        default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); 
    104127         
     
    757780                                         
    758781                                        if(variables[j] == "locator") { 
    759782                                                // special case for locator 
    760                                                 var text = citationItem && citationItem.locator ? citationItem.locator : ""; 
     783/* 
     784 * fbennett (3): strip quotes from locator: 
     785 */ 
     786                                                var text = citationItem && citationItem.locator ? item.stripQuotes(citationItem.locator) : ""; 
     787/* 
     788 * fbennett: end 
     789 */ 
    761790                                        } else if(citationItem && citationItem._csl && citationItem._csl[variables[j]]) { 
    762791                                                // override if requested 
    763792                                                var text = citationItem._csl[variables[j]]; 
     
    10361065                                         
    10371066                                        // inspect variables 
    10381067                                        var done = false; 
    1039                                         var attributes = ["variable", "is-date", "is-numeric", "is-plural", "type", "disambiguate", "locator", "position"]; 
     1068/* 
     1069 * fbennett (3): add "is-quoted" to attributes list 
     1070 */ 
     1071                                        var attributes = ["variable","is-date", "is-numeric", "is-plural", "type", "disambiguate","locator","position","is-quoted"]; 
     1072/* 
     1073 * fbennett: end 
     1074 */ 
    10401075                                        for(var k=0; !done && k<attributes.length; k++) { 
    10411076                                                var attribute = attributes[k]; 
    10421077                                                 
     
    10871122                                                                        exists = citationItem && citationItem.locator && 
    10881123                                                                                (citationItem.locatorType == variables[j] 
    10891124                                                                                || (!citationItem.locatorType && variables[j] == "page")); 
     1125/* 
     1126 * fbennett (3): adding is-quoted condition 
     1127 */ 
     1128                                                                } else if (attribute == "is-quoted") { 
     1129                                                                    //special handling for locator 
     1130                                                                    if(variables[j] == "locator") { 
     1131                                                                        exists = citationItem && citationItem.locator ? citationItem.locator.match(Zotero.CSL._quotedRegexp) : "" 
     1132                                                                    } else { 
     1133                                                                        exists = item.getVariable(variables[j],"nostrip").match(Zotero.CSL._quotedRegexp); 
     1134                                                                    } 
     1135/* 
     1136 * fbennett: end 
     1137 */ 
    10901138                                                                } else {        // attribute == "position" 
    10911139                                                                        if(variables[j] == "first") { 
    10921140                                                                                exists = !citationItem 
     
    18241872         
    18251873        for each(var zoteroField in zoteroFields) { 
    18261874                var value = this.zoteroItem.getField(zoteroField, false, true); 
    1827                 if(value != "") return value + ''; 
     1875/* 
     1876 * fbennett (3): strip quotes from field if form != "nostrip" 
     1877 */ 
     1878                if(value != "") return this.stripQuotes(value, form) + ''; 
     1879/* 
     1880 * fbennett: end 
     1881 */ 
    18281882        } 
    18291883         
    18301884        return ""; 
     
    20622116} 
    20632117 
    20642118/* 
     2119 * fbennett: (3): add function to strip double-quotation marks from a string 
     2120 */ 
     2121 Zotero.CSL.Item.prototype.stripQuotes = function(value,form) { 
     2122     if(typeof(value) == "string" && value.substr(0,1) == '"' && value.substr(value.length-1,1) == '"' && form != "nostrip") { 
     2123        return value.slice(1,value.length-1); 
     2124    } else { 
     2125        return value; 
     2126    } 
     2127} 
     2128/* 
     2129 * fbennett: end 
     2130 */ 
     2131 
     2132/* 
    20652133 * Date class 
    20662134 */ 
    20672135Zotero.CSL.Item.Date = function(date, sort) {