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 2 2 "translatorID":"9cb70025-a888-4a29-a210-93ec52da40d4", 3 3 "translatorType":3, 4 4 "label":"BibTeX", 5 "creator":"Simon Kornblith ",5 "creator":"Simon Kornblith and Richard Karnesky", 6 6 "target":"bib", 7 7 "minVersion":"1.0.0b4.r1", 8 8 "maxVersion":"", … … var fieldMap = { 62 62 address:"place", 63 63 chapter:"section", 64 64 edition:"edition", 65 // number:"issue",66 65 type:"type", 67 66 series:"series", 68 67 title:"title", … … var fieldMap = { 72 71 issn:"ISSN", 73 72 lccn:"callNumber", 74 73 location:"archiveLocation", 74 shorttitle:"shortTitle", 75 75 url:"url", 76 76 doi:"DOI", 77 77 "abstract":"abstractNote" … … var inputFieldMap = { 86 86 87 87 var zotero2bibtexTypeMap = { 88 88 "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", 99 90 "journalArticle":"article", 100 91 "magazineArticle":"article", 101 92 "newspaperArticle":"article", … … var bibtex2zoteroTypeMap = { 121 112 "conference":"conferencePaper", 122 113 "techreport":"report", 123 114 "booklet":"book", 124 "incollection":"bookSection",125 115 "manual":"book", 126 116 "mastersthesis":"thesis", 127 117 "misc":"book", … … var bibtex2zoteroTypeMap = { 134 124 * LaTeX book.) 135 125 */ 136 126 var months = ["jan", "feb", "mar", "apr", "may", "jun", 137 "jul", "aug", "sep", "oct", "nov", "dec"] 127 "jul", "aug", "sep", "oct", "nov", "dec"]; 138 128 139 129 /* 140 130 * new mapping table based on that from Matthias Steffens, … … var mappingTable = { 873 863 "\u013C":"\\c{l}", // LATIN SMALL LETTER L WITH CEDILLA 874 864 "\u013D":"\\v{L}", // LATIN CAPITAL LETTER L WITH CARON 875 865 "\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 876 868 "\u0143":"\\'{N}", // LATIN CAPITAL LETTER N WITH ACUTE 877 869 "\u0144":"\\'{n}", // LATIN SMALL LETTER N WITH ACUTE 878 870 "\u0145":"\\c{N}", // LATIN CAPITAL LETTER N WITH CEDILLA … … var mappingTable = { 1054 1046 "\u1EF4":"\\d{Y}", // LATIN CAPITAL LETTER Y WITH DOT BELOW 1055 1047 "\u1EF5":"\\d{y}", // LATIN SMALL LETTER Y WITH DOT BELOW 1056 1048 "\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 1059 1050 }; 1060 1051 1061 1052 /* unfortunately the mapping isn't reversible - hence this second table - sigh! */ … … var reversemappingTable = { 1108 1099 "{\\OE}" : "\u0152", // LATIN CAPITAL LIGATURE OE 1109 1100 "{\\oe}" : "\u0153", // LATIN SMALL LIGATURE OE 1110 1101 "{\\textasciicircum}" : "\u02C6", // MODIFIER LETTER CIRCUMFLEX ACCENT 1111 "\\~{}" : "\u02DC", // SMALL TILDE1102 // "\\~{}" : "\u02DC", // SMALL TILDE 1112 1103 "{\\textacutedbl}" : "\u02DD", // DOUBLE ACUTE ACCENT 1113 1104 "{\\textendash}" : "\u2013", // EN DASH 1114 1105 "{\\textemdash}" : "\u2014", // EM DASH … … var reversemappingTable = { 1122 1113 "{\\textquotedblleft}" : "\u201C", // LEFT DOUBLE QUOTATION MARK 1123 1114 "{\\textquotedblright}" : "\u201D", // RIGHT DOUBLE QUOTATION MARK 1124 1115 "{\\quotedblbase}" : "\u201E", // DOUBLE LOW-9 QUOTATION MARK 1125 "{\\quotedblbase}" : "\u201F", // DOUBLE HIGH-REVERSED-9 QUOTATION MARK1116 // "{\\quotedblbase}" : "\u201F", // DOUBLE HIGH-REVERSED-9 QUOTATION MARK 1126 1117 "{\\textdagger}" : "\u2020", // DAGGER 1127 1118 "{\\textdaggerdbl}" : "\u2021", // DOUBLE DAGGER 1128 1119 "{\\textbullet}" : "\u2022", // BULLET … … var reversemappingTable = { 1204 1195 "||" : "\u2225", // PARALLEL TO 1205 1196 "\\~{}" : "\u223C", // TILDE OPERATOR 1206 1197 "/=" : "\u2260", // NOT EQUAL TO 1207 "<=" : "\u2264", // LESS-THAN OR EQUAL TO1198 // "<=" : "\u2264", // LESS-THAN OR EQUAL TO 1208 1199 ">=" : "\u2265", // GREATER-THAN OR EQUAL TO 1209 1200 "<<" : "\u226A", // MUCH LESS-THAN 1210 1201 ">>" : "\u226B", // MUCH GREATER-THAN … … var reversemappingTable = { 1214 1205 "(/)" : "\u2298", // CIRCLED DIVISION SLASH 1215 1206 "|-" : "\u22A2", // RIGHT TACK 1216 1207 "-|" : "\u22A3", // LEFT TACK 1217 "|-" : "\u22A6", // ASSERTION1208 // "|-" : "\u22A6", // ASSERTION 1218 1209 "|=" : "\u22A7", // MODELS 1219 "|=" : "\u22A8", // TRUE1210 // "|=" : "\u22A8", // TRUE 1220 1211 "||-" : "\u22A9", // FORCES 1221 1212 "$\\#$" : "\u22D5", // EQUAL AND PARALLEL TO 1222 1213 "<<<" : "\u22D8", // VERY MUCH LESS-THAN … … var reversemappingTable = { 1229 1220 ":-(" : "\u2639", // WHITE FROWNING FACE 1230 1221 ":-)" : "\u263A", // WHITE SMILING FACE 1231 1222 "(-: " : "\u263B", // BLACK SMILING FACE 1232 "$\\#$" : "\u266F", // MUSIC SHARP SIGN1223 // "$\\#$" : "\u266F", // MUSIC SHARP SIGN 1233 1224 "$\\%<$" : "\u2701", // UPPER BLADE SCISSORS 1234 "$\\%<$" : "\u2702", // BLACK SCISSORS1225 /* "$\\%<$" : "\u2702", // BLACK SCISSORS 1235 1226 "$\\%<$" : "\u2703", // LOWER BLADE SCISSORS 1236 "$\\%<$" : "\u2704", // WHITE SCISSORS 1227 "$\\%<$" : "\u2704", // WHITE SCISSORS */ 1237 1228 /* Derived accented characters */ 1238 1229 "\\`{A}" : "\u00C0", // LATIN CAPITAL LETTER A WITH GRAVE 1239 1230 "\\'{A}" : "\u00C1", // LATIN CAPITAL LETTER A WITH ACUTE … … var reversemappingTable = { 1341 1332 "\\c{l}" : "\u013C", // LATIN SMALL LETTER L WITH CEDILLA 1342 1333 "\\v{L}" : "\u013D", // LATIN CAPITAL LETTER L WITH CARON 1343 1334 "\\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 1344 1337 "\\'{N}" : "\u0143", // LATIN CAPITAL LETTER N WITH ACUTE 1345 1338 "\\'{n}" : "\u0144", // LATIN SMALL LETTER N WITH ACUTE 1346 1339 "\\c{N}" : "\u0145", // LATIN CAPITAL LETTER N WITH CEDILLA … … var reversemappingTable = { 1522 1515 "\\d{Y}" : "\u1EF4", // LATIN CAPITAL LETTER Y WITH DOT BELOW 1523 1516 "\\d{y}" : "\u1EF5", // LATIN SMALL LETTER Y WITH DOT BELOW 1524 1517 "\\~{Y}" : "\u1EF8", // LATIN CAPITAL LETTER Y WITH TILDE 1525 "\\~{y}" : "\u1EF9" ,// LATIN SMALL LETTER Y WITH TILDE1518 "\\~{y}" : "\u1EF9" // LATIN SMALL LETTER Y WITH TILDE 1526 1519 }; 1527 1520 1528 1521 var alwaysMap = { … … var alwaysMap = { 1534 1527 "\\":"{\\textbackslash}" 1535 1528 }; 1536 1529 1537 var strings = new Object();1530 var strings = {}; 1538 1531 var keyRe = /[a-zA-Z0-9\-]/; 1539 1532 1540 1533 function processField(item, field, value) { … … function processField(item, field, value) { 1544 1537 item[inputFieldMap[field]] = value; 1545 1538 } else if(field == "journal") { 1546 1539 if(item.publicationTitle) { 1547 // we already had an fjournal 1548 item.journalAbbreviation = value 1540 item.journalAbbreviation = value; 1549 1541 } else { 1550 1542 item.publicationTitle = value; 1551 1543 } … … function processField(item, field, value) { 1555 1547 item.journalAbbreviation = value; 1556 1548 } 1557 1549 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 1560 1552 var names = value.split(/ and /i); // now case insensitive 1561 1553 for each(var name in names) { 1562 1554 item.creators.push(Zotero.Utilities.cleanAuthor(name, field, … … function processField(item, field, value) { 1567 1559 } else if(field == "number"){ // fix for techreport 1568 1560 if (item.itemType == "report") { 1569 1561 item.reportNumber = value; 1562 } else if (item.itemType == "book" || item.itemType == "bookSection") { 1563 item.seriesNumber = value; 1570 1564 } else { 1571 1565 item.issue = value; 1572 1566 } … … function processField(item, field, value) { 1599 1593 } 1600 1594 } else if(field == "pages") { 1601 1595 item.pages = value.replace(/--/g, "-"); 1602 } else if(field == "note" || field == "annote") {1596 } else if(field == "note") { 1603 1597 item.extra += "\n"+value; 1604 1598 } else if(field == "howpublished") { 1605 1599 if(value.length >= 7) { … … function processField(item, field, value) { 1617 1611 } else { 1618 1612 item.tags = value.split(/, ?/g); 1619 1613 } 1620 } else if (field == "comment" ) {1614 } else if (field == "comment" || field == "annote" || field == "review") { 1621 1615 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 } 1625 1635 } 1626 1636 1627 1637 function getFieldValue(read) { … … function getFieldValue(read) { 1690 1700 if(value[0] == "\\" && "#$%&~_^\\{}".indexOf(value[1]) != -1) { 1691 1701 value = value.substr(1); 1692 1702 } 1693 if(value[value.length-1] == "\\" && "#$%&~_^\\{}".indexOf(value[value.length-2]) != -1) {1703 if(value[value.length-1] == "\\" && "#$%&~_^\\{}".indexOf(value[value.length-2]) != -1) { 1694 1704 value = value.substr(0, value.length-1); 1695 1705 } 1696 1706 value = value.replace(/\\\\/g, "\\"); … … function doExport() { 1927 1937 } 1928 1938 } 1929 1939 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); 1932 1942 } 1933 1943 1934 1944 if(item.publicationTitle) { … … function doExport() { 1953 1963 // split creators into subcategories 1954 1964 var author = ""; 1955 1965 var editor = ""; 1966 var translator = ""; 1956 1967 for each(var creator in item.creators) { 1957 1968 var creatorString = creator.lastName; 1958 1969 … … function doExport() { 1962 1973 1963 1974 if (creator.creatorType == "editor") { 1964 1975 editor += " and "+creatorString; 1976 } else if (creator.creatorType == "translator") { 1977 translator += " and "+creatorString; 1965 1978 } else { 1966 1979 author += " and "+creatorString; 1967 1980 } … … function doExport() { 1973 1986 if(editor) { 1974 1987 writeField("editor", editor.substr(5)); 1975 1988 } 1989 if(translator) { 1990 writeField("translator", translator.substr(5)); 1991 } 1976 1992 } 1977 1993 1978 1994 if(item.date) { … … function doExport() { 1993 2009 if(item.tags && item.tags.length) { 1994 2010 var tagString = ""; 1995 2011 for each(var tag in item.tags) { 1996 tagString += ", "+tag.tag;2012 tagString += ", "+tag.tag; 1997 2013 } 1998 writeField("keywords", tagString.substr( 1));2014 writeField("keywords", tagString.substr(2)); 1999 2015 } 2000 2016 2001 2017 if(item.pages) { … … function doExport() { 2007 2023 } 2008 2024 if (item.notes) { 2009 2025 for each (var note in item.notes) { 2010 writeField(" comment", note["note"]);2026 writeField("annote", note["note"]); 2011 2027 } 2012 2028 } 2013 2029 Zotero.write("\n}");