@citation-js/plugin-bibtex
Advanced tools
Comparing version 0.7.11 to 0.7.12
@@ -17,2 +17,3 @@ import biblatex from './mapping/biblatexTypes.json'; | ||
useIdAsLabel: false, | ||
checkLabel: true, | ||
asciiOnly: true | ||
@@ -19,0 +20,0 @@ }, |
@@ -6,2 +6,16 @@ import { util } from '@citation-js/core'; | ||
const unicode = /[^\u0020-\u007F]+/g; | ||
function isLabelSafe(text) { | ||
return !config.format.checkLabel || !text.match(unsafeChars); | ||
} | ||
function formatLabelFromId(id) { | ||
if (id === null) { | ||
return 'null'; | ||
} else if (id === undefined) { | ||
return 'undefined'; | ||
} else if (config.format.checkLabel) { | ||
return id.toString().replace(unsafeChars, ''); | ||
} else { | ||
return id.toString(); | ||
} | ||
} | ||
function firstWord(text) { | ||
@@ -231,17 +245,8 @@ if (!text) { | ||
toSource(id, label, author, issued, suffix, title) { | ||
let safeId; | ||
if (id === null) { | ||
safeId = 'null'; | ||
} else if (id === undefined) { | ||
safeId = 'undefined'; | ||
} else { | ||
safeId = id.toString().replace(unsafeChars, ''); | ||
} | ||
if (config.format.useIdAsLabel) { | ||
return safeId; | ||
} | ||
if (label && !unsafeChars.test(label)) { | ||
if (label && isLabelSafe(label)) { | ||
return label; | ||
} else if (config.format.useIdAsLabel) { | ||
return formatLabelFromId(id); | ||
} else { | ||
return formatLabel(author, issued, suffix, title) || safeId; | ||
return formatLabel(author, issued, suffix, title) || formatLabelFromId(id); | ||
} | ||
@@ -248,0 +253,0 @@ } |
@@ -26,2 +26,3 @@ "use strict"; | ||
useIdAsLabel: false, | ||
checkLabel: true, | ||
asciiOnly: true | ||
@@ -28,0 +29,0 @@ }, |
@@ -16,2 +16,16 @@ "use strict"; | ||
const unicode = /[^\u0020-\u007F]+/g; | ||
function isLabelSafe(text) { | ||
return !_config.default.format.checkLabel || !text.match(unsafeChars); | ||
} | ||
function formatLabelFromId(id) { | ||
if (id === null) { | ||
return 'null'; | ||
} else if (id === undefined) { | ||
return 'undefined'; | ||
} else if (_config.default.format.checkLabel) { | ||
return id.toString().replace(unsafeChars, ''); | ||
} else { | ||
return id.toString(); | ||
} | ||
} | ||
function firstWord(text) { | ||
@@ -241,17 +255,8 @@ if (!text) { | ||
toSource(id, label, author, issued, suffix, title) { | ||
let safeId; | ||
if (id === null) { | ||
safeId = 'null'; | ||
} else if (id === undefined) { | ||
safeId = 'undefined'; | ||
} else { | ||
safeId = id.toString().replace(unsafeChars, ''); | ||
} | ||
if (_config.default.format.useIdAsLabel) { | ||
return safeId; | ||
} | ||
if (label && !unsafeChars.test(label)) { | ||
if (label && isLabelSafe(label)) { | ||
return label; | ||
} else if (_config.default.format.useIdAsLabel) { | ||
return formatLabelFromId(id); | ||
} else { | ||
return formatLabel(author, issued, suffix, title) || safeId; | ||
return formatLabel(author, issued, suffix, title) || formatLabelFromId(id); | ||
} | ||
@@ -258,0 +263,0 @@ } |
{ | ||
"name": "@citation-js/plugin-bibtex", | ||
"version": "0.7.11", | ||
"version": "0.7.12", | ||
"description": "Plugin for BibTeX formats for Citation.js", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a92f6b3c20b9342feb0303a017b806b312d66486" | ||
"gitHead": "1fe938dcd9986c52353c2f971f677e7d6f93839d" | ||
} |
@@ -61,2 +61,4 @@ # @citation-js/plugin-bibtex | ||
| `config.format.useIdAsLabel` | `true`, [`false`] | Use the entry ID as the label instead of generating one. | | ||
| `config.format.checkLabel` | [`true`], `false` | Remove unsafe characters from the provided label (or ID). | | ||
| `config.format.asciiOnly` | [`true`], `false` | Escape or remove non-ASCII characters. | | ||
@@ -63,0 +65,0 @@ ### Type mappings |
199693
6176
194