Ticket #439: 25-alternative-font-markup.patch

File 25-alternative-font-markup.patch, 3.6 KB (added by fbennett, 8 years ago)

Implements alternative typefaces, rm to italic, italic to rm

  • chrome/content/zotero/xpcom/csl.js

    Only in zotero-trunk/chrome/content/zotero: about.xul~
    Only in zotero-trunk/chrome/content/zotero: lexdowngradewizard.xul~
    Only in zotero-trunk/chrome/content/zotero: lexupgradewizard.xul~
    Only in zotero-trunk/chrome/content/zotero: overlay.xul~
    Only in zotero-trunk/chrome/content/zotero: upgrade.xul~
    diff -u -r zotero-trunk.orig/chrome/content/zotero/xpcom/csl.js zotero-trunk/chrome/content/zotero/xpcom/csl.js
    old new  
    22    ***** BEGIN LICENSE BLOCK ***** 
    33     
    44    Copyright (c) 2006  Center for History and New Media 
    5                         George Mason University, Fairfax, Virginia, USA 
     5                       George Mason University, Fairfax, Virginia, USA 
    66                        http://chnm.gmu.edu 
    77     
    88    Licensed under the Educational Community License, Version 1.0 (the "License"); 
     
    814814                                                success = true; 
    815815                                        } 
    816816                                } 
    817                                  
    818817                                if(success) { 
    819                                         formattedString.concat(newString, child); 
     818                                        // see comment to Zotero.CSL.FormattedString.prototype.concat, below 
     819                                        formattedString.concat(newString, child, true); 
    820820                                        dataAppended = true; 
    821821                                } 
    822822                        } else if(child.@macro.length()) { 
     
    26732673} 
    26742674 
    26752675Zotero.CSL.FormattedString._punctuation = "!.,?:"; 
     2676Zotero.CSL.FormattedString._faces = ['normal','italic']; 
    26762677 
    26772678/* 
    26782679 * attaches another formatted string to the end of the current one 
     2680 *  
     2681 * parameter textTagFlag limits alternative font markup parsing to strings 
     2682 * as passed immediately from a <text variable="XX"/> tag.  Strings 
     2683 * passed by <text macro=XX"/> are not parsed. 
    26792684 */ 
    2680 Zotero.CSL.FormattedString.prototype.concat = function(formattedString, element) { 
     2685Zotero.CSL.FormattedString.prototype.concat = function(formattedString, element, textTagFlag) { 
    26812686        default xml namespace = "http://purl.org/net/xbiblio/csl"; with({}); 
    26822687         
    26832688        if(!formattedString || !formattedString.string) { 
     
    26992704                        suffix = element.@suffix.toString(); 
    27002705                        element.@suffix = []; 
    27012706                } 
    2702                 haveAppended = this.append(formattedString.string, element, false, true); 
     2707                // apply alternative typeface, rm->it, it->rm according 
     2708                // to paired asterisks.  double asterisk is escape. 
     2709                // 
     2710                var string = formattedString.string.replace(/\*\*/g, "[[ASTERISK]]"); 
     2711                // save the effort in most cases 
     2712                if ( textTagFlag && string.match(/.*\*[^*]+\*.*/)) { 
     2713                        var start = 0; 
     2714                        if ( element && element['@font-style'] == 'italic' ) { 
     2715                                var start = 1; 
     2716                        } 
     2717                        if (string.indexOf("*") == 0 ) { 
     2718                                var start = ( start + 1 ) % 2; 
     2719                        } 
     2720                        var split = string.split(/\*([^*]+)\*/); 
     2721                        for (i=0; i<split.length; i++) { 
     2722                                pos = ( start + i ) % 2; 
     2723                                element['@font-style'] = Zotero.CSL.FormattedString._faces[pos]; 
     2724                                this.append(split[i].replace(/\[\[ASTERISK\]\]/g, "*"), element, false, true); 
     2725                                if (i == 0) { 
     2726                                        element.@prefix = []; 
     2727                                } 
     2728                        } 
     2729                        haveAppended = true; 
     2730                } else { 
     2731                        haveAppended = this.append(formattedString.string, element, false, true); 
     2732                } 
    27032733        } 
    27042734         
    27052735        // if there's close punctuation to append, that also counts 
     
    27312761        if(typeof(string) != "string") { 
    27322762                string = string.toString(); 
    27332763        } 
    2734          
     2764 
    27352765        // get prefix 
    27362766        var prefix = ""; 
    27372767        if(element && element.@prefix.length()) {