Skip to content

Commit

Permalink
Clean BibTeX citekey more rigourosly in the future
Browse files Browse the repository at this point in the history
This superseeds #1013.
  • Loading branch information
zuphilip committed Dec 7, 2019
1 parent f05edd5 commit 4cada1b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions BibTeX.js
Expand Up @@ -18,7 +18,7 @@
},
"inRepository": true,
"translatorType": 3,
"lastUpdated": "2019-10-12 20:32:44"
"lastUpdated": "2019-11-30 10:00:00"
}

/*
Expand Down Expand Up @@ -1210,7 +1210,6 @@ var numberRe = /^[0-9]+/;
// Also remove markup
var citeKeyTitleBannedRe = /\b(a|an|the|some|from|on|in|to|of|do|with|der|die|das|ein|eine|einer|eines|einem|einen|un|une|la|le|l\'|el|las|los|al|uno|una|unos|unas|de|des|del|d\')(\s+|\b)|(<\/?(i|b|sup|sub|sc|span style=\"small-caps\"|span)>)/g;
var citeKeyConversionsRe = /%([a-zA-Z])/;
var citeKeyCleanRe = /[^a-z0-9\!\$\&\*\+\-\.\/\:\;\<\>\?\[\]\^\_\`\|]+/g;

var citeKeyConversions = {
"a":function (flags, item) {
Expand Down Expand Up @@ -1282,6 +1281,15 @@ function buildCiteKey (item, extraFields, citekeys) {
// however, we want to keep the base characters

basekey = tidyAccents(basekey);
// use legacy pattern for all old items to not break existing usages
var citeKeyCleanRe = /[^a-z0-9\!\$\&\*\+\-\.\/\:\;\<\>\?\[\]\^\_\`\|]+/g;
// but use the simple pattern for all newly added items
// or always if the hiddenPref is set
// extensions.zotero.translators.BibTeX.export.simpleCitekey
if ((Zotero.getHiddenPref && Zotero.getHiddenPref('BibTeX.export.simpleCitekey'))
|| (item.dateAdded && parseInt(item.dateAdded.substr(0, 4)) >= 2020)) {
citeKeyCleanRe = /[^a-z0-9_-]/g;
}
basekey = basekey.replace(citeKeyCleanRe, "");
var citekey = basekey;
var i = 0;
Expand Down

0 comments on commit 4cada1b

Please sign in to comment.