Ticket #1514: BibTeX.js.diff

File BibTeX.js.diff, 12.8 KB (added by karnesky, 7 years ago)
  • translators/BibTeX.js

    diff --git a/translators/BibTeX.js b/translators/BibTeX.js
    index 9708011..f945b46 100644
    a b  
    22        "translatorID":"9cb70025-a888-4a29-a210-93ec52da40d4", 
    33        "translatorType":3, 
    44        "label":"BibTeX", 
    5         "creator":"Simon Kornblith", 
     5        "creator":"Simon Kornblith and Richard Karnesky", 
    66        "target":"bib", 
    77        "minVersion":"1.0.0b4.r1", 
    88        "maxVersion":"", 
    var fieldMap = { 
    6262        address:"place", 
    6363        chapter:"section", 
    6464        edition:"edition", 
    65 //      number:"issue", 
    6665        type:"type", 
    6766        series:"series", 
    6867        title:"title", 
    var fieldMap = { 
    7271        issn:"ISSN", 
    7372        lccn:"callNumber", 
    7473        location:"archiveLocation", 
     74        shorttitle:"shortTitle", 
    7575        url:"url", 
    7676        doi:"DOI", 
    7777        "abstract":"abstractNote" 
    var inputFieldMap = { 
    8686 
    8787var zotero2bibtexTypeMap = { 
    8888        "book":"book", 
    89         "bookSection": function (item) { 
    90                 var hasAuthor = false; 
    91                 var hasEditor = false; 
    92                 for each(var creator in item.creators) { 
    93                         if (creator.creatorType == "editor") { hasEditor = true; } 
    94                         if (creator.creatorType == "author") { hasAuthor = true; } 
    95                 } 
    96                 if (hasAuthor && hasEditor) { return "incollection"; } 
    97                 return "inbook"; 
    98                 }, 
     89        "bookSection":"incollection", 
    9990        "journalArticle":"article", 
    10091        "magazineArticle":"article", 
    10192        "newspaperArticle":"article", 
    var bibtex2zoteroTypeMap = { 
    121112        "conference":"conferencePaper", 
    122113        "techreport":"report", 
    123114        "booklet":"book", 
    124         "incollection":"bookSection", 
    125115        "manual":"book", 
    126116        "mastersthesis":"thesis", 
    127117        "misc":"book", 
    var bibtex2zoteroTypeMap = { 
    134124 * LaTeX book.) 
    135125 */ 
    136126var months = ["jan", "feb", "mar", "apr", "may", "jun", 
    137               "jul", "aug", "sep", "oct", "nov", "dec"] 
     127              "jul", "aug", "sep", "oct", "nov", "dec"]; 
    138128 
    139129/* 
    140130 * new mapping table based on that from Matthias Steffens, 
    var mappingTable = { 
    873863    "\u013C":"\\c{l}", // LATIN SMALL LETTER L WITH CEDILLA 
    874864    "\u013D":"\\v{L}", // LATIN CAPITAL LETTER L WITH CARON 
    875865    "\u013E":"\\v{l}", // LATIN SMALL LETTER L WITH CARON 
     866    "\u0141":"\\L{}", //LATIN CAPITAL LETTER L WITH STROKE 
     867    "\u0142":"\\l{}", //LATIN SMALL LETTER L WITH STROKE 
    876868    "\u0143":"\\'{N}", // LATIN CAPITAL LETTER N WITH ACUTE 
    877869    "\u0144":"\\'{n}", // LATIN SMALL LETTER N WITH ACUTE 
    878870    "\u0145":"\\c{N}", // LATIN CAPITAL LETTER N WITH CEDILLA 
    var mappingTable = { 
    10541046    "\u1EF4":"\\d{Y}", // LATIN CAPITAL LETTER Y WITH DOT BELOW 
    10551047    "\u1EF5":"\\d{y}", // LATIN SMALL LETTER Y WITH DOT BELOW 
    10561048    "\u1EF8":"\\~{Y}", // LATIN CAPITAL LETTER Y WITH TILDE 
    1057     "\u1EF9":"\\~{y}", // LATIN SMALL LETTER Y WITH TILDE 
    1058  
     1049    "\u1EF9":"\\~{y}" // LATIN SMALL LETTER Y WITH TILDE 
    10591050}; 
    10601051 
    10611052/* unfortunately the mapping isn't reversible - hence this second table - sigh! */ 
    var reversemappingTable = { 
    11081099    "{\\OE}"                          : "\u0152", // LATIN CAPITAL LIGATURE OE 
    11091100    "{\\oe}"                          : "\u0153", // LATIN SMALL LIGATURE OE 
    11101101    "{\\textasciicircum}"             : "\u02C6", // MODIFIER LETTER CIRCUMFLEX ACCENT 
    1111     "\\~{}"                           : "\u02DC", // SMALL TILDE 
     1102//    "\\~{}"                           : "\u02DC", // SMALL TILDE 
    11121103    "{\\textacutedbl}"                : "\u02DD", // DOUBLE ACUTE ACCENT 
    11131104    "{\\textendash}"                  : "\u2013", // EN DASH 
    11141105    "{\\textemdash}"                  : "\u2014", // EM DASH 
    var reversemappingTable = { 
    11221113    "{\\textquotedblleft}"            : "\u201C", // LEFT DOUBLE QUOTATION MARK 
    11231114    "{\\textquotedblright}"           : "\u201D", // RIGHT DOUBLE QUOTATION MARK 
    11241115    "{\\quotedblbase}"                : "\u201E", // DOUBLE LOW-9 QUOTATION MARK 
    1125     "{\\quotedblbase}"                : "\u201F", // DOUBLE HIGH-REVERSED-9 QUOTATION MARK 
     1116//    "{\\quotedblbase}"                : "\u201F", // DOUBLE HIGH-REVERSED-9 QUOTATION MARK 
    11261117    "{\\textdagger}"                  : "\u2020", // DAGGER 
    11271118    "{\\textdaggerdbl}"               : "\u2021", // DOUBLE DAGGER 
    11281119    "{\\textbullet}"                  : "\u2022", // BULLET 
    var reversemappingTable = { 
    12041195    "||"                              : "\u2225", // PARALLEL TO 
    12051196    "\\~{}"                           : "\u223C", // TILDE OPERATOR 
    12061197    "/="                              : "\u2260", // NOT EQUAL TO 
    1207     "<="                              : "\u2264", // LESS-THAN OR EQUAL TO 
     1198//    "<="                              : "\u2264", // LESS-THAN OR EQUAL TO 
    12081199    ">="                              : "\u2265", // GREATER-THAN OR EQUAL TO 
    12091200    "<<"                              : "\u226A", // MUCH LESS-THAN 
    12101201    ">>"                              : "\u226B", // MUCH GREATER-THAN 
    var reversemappingTable = { 
    12141205    "(/)"                             : "\u2298", // CIRCLED DIVISION SLASH 
    12151206    "|-"                              : "\u22A2", // RIGHT TACK 
    12161207    "-|"                              : "\u22A3", // LEFT TACK 
    1217     "|-"                              : "\u22A6", // ASSERTION 
     1208//    "|-"                              : "\u22A6", // ASSERTION 
    12181209    "|="                              : "\u22A7", // MODELS 
    1219     "|="                              : "\u22A8", // TRUE 
     1210//    "|="                              : "\u22A8", // TRUE 
    12201211    "||-"                             : "\u22A9", // FORCES 
    12211212    "$\\#$"                           : "\u22D5", // EQUAL AND PARALLEL TO 
    12221213    "<<<"                             : "\u22D8", // VERY MUCH LESS-THAN 
    var reversemappingTable = { 
    12291220    ":-("                             : "\u2639", // WHITE FROWNING FACE 
    12301221    ":-)"                             : "\u263A", // WHITE SMILING FACE 
    12311222    "(-: "                            : "\u263B", // BLACK SMILING FACE 
    1232     "$\\#$"                           : "\u266F", // MUSIC SHARP SIGN 
     1223//    "$\\#$"                           : "\u266F", // MUSIC SHARP SIGN 
    12331224    "$\\%<$"                          : "\u2701", // UPPER BLADE SCISSORS 
    1234     "$\\%<$"                          : "\u2702", // BLACK SCISSORS 
     1225/*    "$\\%<$"                          : "\u2702", // BLACK SCISSORS 
    12351226    "$\\%<$"                          : "\u2703", // LOWER BLADE SCISSORS 
    1236     "$\\%<$"                          : "\u2704", // WHITE SCISSORS 
     1227    "$\\%<$"                          : "\u2704", // WHITE SCISSORS */ 
    12371228/* Derived accented characters */ 
    12381229    "\\`{A}"                          : "\u00C0", // LATIN CAPITAL LETTER A WITH GRAVE 
    12391230    "\\'{A}"                          : "\u00C1", // LATIN CAPITAL LETTER A WITH ACUTE 
    var reversemappingTable = { 
    13411332    "\\c{l}"                          : "\u013C", // LATIN SMALL LETTER L WITH CEDILLA 
    13421333    "\\v{L}"                          : "\u013D", // LATIN CAPITAL LETTER L WITH CARON 
    13431334    "\\v{l}"                          : "\u013E", // LATIN SMALL LETTER L WITH CARON 
     1335    "\\L{}"                           : "\u0141", //LATIN CAPITAL LETTER L WITH STROKE 
     1336    "\\l{}"                           : "\u0142", //LATIN SMALL LETTER L WITH STROKE 
    13441337    "\\'{N}"                          : "\u0143", // LATIN CAPITAL LETTER N WITH ACUTE 
    13451338    "\\'{n}"                          : "\u0144", // LATIN SMALL LETTER N WITH ACUTE 
    13461339    "\\c{N}"                          : "\u0145", // LATIN CAPITAL LETTER N WITH CEDILLA 
    var reversemappingTable = { 
    15221515    "\\d{Y}"                          : "\u1EF4", // LATIN CAPITAL LETTER Y WITH DOT BELOW 
    15231516    "\\d{y}"                          : "\u1EF5", // LATIN SMALL LETTER Y WITH DOT BELOW 
    15241517    "\\~{Y}"                          : "\u1EF8", // LATIN CAPITAL LETTER Y WITH TILDE 
    1525     "\\~{y}"                          : "\u1EF9", // LATIN SMALL LETTER Y WITH TILDE 
     1518    "\\~{y}"                          : "\u1EF9" // LATIN SMALL LETTER Y WITH TILDE 
    15261519}; 
    15271520 
    15281521var alwaysMap = { 
    var alwaysMap = { 
    15341527        "\\":"{\\textbackslash}" 
    15351528}; 
    15361529 
    1537 var strings = new Object(); 
     1530var strings = {}; 
    15381531var keyRe = /[a-zA-Z0-9\-]/; 
    15391532 
    15401533function processField(item, field, value) { 
    function processField(item, field, value) { 
    15441537                item[inputFieldMap[field]] = value; 
    15451538        } else if(field == "journal") { 
    15461539                if(item.publicationTitle) { 
    1547                         // we already had an fjournal 
    1548                         item.journalAbbreviation = value 
     1540                        item.journalAbbreviation = value; 
    15491541                } else { 
    15501542                        item.publicationTitle = value; 
    15511543                } 
    function processField(item, field, value) { 
    15551547                        item.journalAbbreviation = value; 
    15561548                } 
    15571549                item.publicationTitle = value; 
    1558         } else if(field == "author" || field == "editor") { 
    1559                 // parse authors/editors 
     1550        } else if(field == "author" || field == "editor" || field == "translator") { 
     1551                // parse authors/editors/translators 
    15601552                var names = value.split(/ and /i); // now case insensitive 
    15611553                for each(var name in names) { 
    15621554                        item.creators.push(Zotero.Utilities.cleanAuthor(name, field, 
    function processField(item, field, value) { 
    15671559        } else if(field == "number"){ // fix for techreport 
    15681560                if (item.itemType == "report") { 
    15691561                        item.reportNumber = value; 
     1562                } else if (item.itemType == "book" || item.itemType == "bookSection") { 
     1563                        item.seriesNumber = value; 
    15701564                } else { 
    15711565                        item.issue = value; 
    15721566                } 
    function processField(item, field, value) { 
    15991593                } 
    16001594        } else if(field == "pages") { 
    16011595                item.pages = value.replace(/--/g, "-"); 
    1602         } else if(field == "note" || field == "annote") { 
     1596        } else if(field == "note") { 
    16031597                item.extra += "\n"+value; 
    16041598        } else if(field == "howpublished") { 
    16051599                if(value.length >= 7) { 
    function processField(item, field, value) { 
    16171611                } else { 
    16181612                        item.tags = value.split(/, ?/g); 
    16191613                } 
    1620         } else if (field == "comment") { 
     1614        } else if (field == "comment" || field == "annote" || field == "review") { 
    16211615                item.notes.push({note:value}); 
    1622         } else if(field == "pdf") { // new code to handle PDF import. absolute file path should be specified in bibtex 
    1623         item.attachments = [{url:"file://"+value, mimeType:"application/pdf"}]; 
    1624     } 
     1616        } else if (field == "pdf") { 
     1617                if (/:\/\//.test(value)) { // a full uri is given 
     1618                        item.attachments = [{url:value, mimeType:"application/pdf", downloadable:true}]; 
     1619                } else { // if no uri is given, assume that it is an absolute path to the PDF 
     1620                        item.attachments = [{url:"file://"+value, mimeType:"application/pdf"}]; 
     1621                } 
     1622        } else if (field == "sentelink") { // the reference manager 'Sente' has a unique file scheme in exported BibTeX 
     1623                        item.attachments = [{url:value.split(",")[0], mimeType:"application/pdf", downloadable:true}]; 
     1624        } else if (field == "file") { 
     1625                var [filetitle, filepath, filetype] = value.split(":"); 
     1626                if (filetitle.length == 0) { 
     1627                        filetitle = "Attachment"; 
     1628                } 
     1629                if (filetype.match(/pdf/i)) { 
     1630                        item.attachments = [{url:"file://"+filepath, mimeType:"application/pdf", title:filetitle, downloadable:true}]; 
     1631                } else { 
     1632                        item.attachments = [{url:"file://"+filepath, title:filetitle, downloadable:true}]; 
     1633                } 
     1634        } 
    16251635} 
    16261636 
    16271637function getFieldValue(read) { 
    function getFieldValue(read) { 
    16901700                if(value[0] == "\\" && "#$%&~_^\\{}".indexOf(value[1]) != -1) { 
    16911701                        value = value.substr(1); 
    16921702                } 
    1693                 if(value[value.length-1] == "\\" &&  "#$%&~_^\\{}".indexOf(value[value.length-2]) != -1) { 
     1703                if(value[value.length-1] == "\\" && "#$%&~_^\\{}".indexOf(value[value.length-2]) != -1) { 
    16941704                        value = value.substr(0, value.length-1); 
    16951705                } 
    16961706                value = value.replace(/\\\\/g, "\\"); 
    function doExport() { 
    19271937                        } 
    19281938                } 
    19291939 
    1930                 if(item.reportNumber || item.issue) { 
    1931                         writeField("number", item.reportNumber || item.issue); 
     1940                if(item.reportNumber || item.issue || item.seriesNumber) { 
     1941                        writeField("number", item.reportNumber || item.issue || item.seriesNumber); 
    19321942                } 
    19331943 
    19341944                if(item.publicationTitle) { 
    function doExport() { 
    19531963                        // split creators into subcategories 
    19541964                        var author = ""; 
    19551965                        var editor = ""; 
     1966                        var translator = ""; 
    19561967                        for each(var creator in item.creators) { 
    19571968                                var creatorString = creator.lastName; 
    19581969 
    function doExport() { 
    19621973 
    19631974                                if (creator.creatorType == "editor") { 
    19641975                                        editor += " and "+creatorString; 
     1976                                } else if (creator.creatorType == "translator") { 
     1977                                        translator += " and "+creatorString; 
    19651978                                } else { 
    19661979                                        author += " and "+creatorString; 
    19671980                                } 
    function doExport() { 
    19731986                        if(editor) { 
    19741987                                writeField("editor", editor.substr(5)); 
    19751988                        } 
     1989                        if(translator) { 
     1990                                writeField("translator", translator.substr(5)); 
     1991                        } 
    19761992                } 
    19771993                 
    19781994                if(item.date) { 
    function doExport() { 
    19932009                if(item.tags && item.tags.length) { 
    19942010                        var tagString = ""; 
    19952011                        for each(var tag in item.tags) { 
    1996                                 tagString += ","+tag.tag; 
     2012                                tagString += ", "+tag.tag; 
    19972013                        } 
    1998                         writeField("keywords", tagString.substr(1)); 
     2014                        writeField("keywords", tagString.substr(2)); 
    19992015                } 
    20002016                 
    20012017                if(item.pages) { 
    function doExport() { 
    20072023                } 
    20082024                if (item.notes) { 
    20092025                        for each (var note in item.notes) { 
    2010                                 writeField("comment", note["note"]); 
     2026                                writeField("annote", note["note"]); 
    20112027                        } 
    20122028                }                
    20132029                Zotero.write("\n}");