Ticket #771: scaps-rev2.patch

File scaps-rev2.patch, 1.5 KB (added by fbennett, 7 years ago)

Second revision of small caps patch

  • content/zotero/bindings/styled-textbox.xml

     
    163163                                                for(var needle in this._rtfMap) { 
    164164                                                        output = output.replace(needle, this._rtfMap[needle], "g");  
    165165                                                } 
    166                                                  
     166                                                var l = output.split(/(<\/?span[^>]*>)/); 
     167                                                var current_level = 0; 
     168                                                var tag_level = new Array(); 
     169                                                for (var pos=1; pos<l.length; pos+=2){ 
     170                                                        var tag = l[pos]; 
     171                                                        if (tag.slice(1,2) == "/"){ 
     172                                                                current_level += -1; 
     173                                                                if (current_level == tag_level[(tag_level.length-1)]){ 
     174                                                                        tag_level.pop(); 
     175                                                                        l[pos] = "\\scaps0 "; 
     176                                                                } 
     177                                                        } else { 
     178                                                                if (l[pos].match(/small-caps/)){ 
     179                                                                        l[pos] = "\\scaps "; 
     180                                                                        tag_level.push(current_level); 
     181                                                                } 
     182                                                                current_level += 1; 
     183                                                        }; 
     184                                                }; 
     185                                                output = l.join(""); 
    167186                                                output = output.replace("<p>", "", "g"); 
    168187                                                output = output.replace("</p>", "\\par ", "g"); 
    169188                                                output = output.replace(/<\/?div[^>]*>/g, ""); 
     
    236255                                                                html = html.replace(this._rtfMap[needle], needle, "g"); 
    237256                                                        } 
    238257                                                } 
     258                                                html = html.replace("\\scaps ", "<span style=\"font-variant:small-caps\">", "g"); 
     259                                                html = html.replace("\\scaps0 ", "</span>", "g"); 
    239260                                                html = '<div style="'+bodyStyle+'"><p>'+html.replace("\par ", "</p><p>")+"</p></div>"; 
    240261                                                Zotero.debug("setting content to "+html); 
    241262                                        }