Skip to content

Commit

Permalink
fix(plugin-bibtex): fix numeric id in bibtex label
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderZeilmann authored and larsgw committed Nov 29, 2021
1 parent 6490200 commit 6291843
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/plugin-bibtex/src/mapping/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,14 @@ export const Converters = {
return [label, label]
},
toSource (id, label, author, issued, suffix, title) {
const safeId = (id && id.replace(unsafeChars, '')) || 'undefined'
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
}
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-bibtex/test/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
"label": [[
{"id": "b", "citation-label": "foo", "type": "book"},
{"id": "b", "author": [{"given": "foo"}], "type": "book"},
{"id": "b", "type": "book"}
{"id": "b", "type": "book"},
{"id": 123, "type": "book"},
{"id": 0, "type": "book"},
{"type": "book"},
{"id": null, "type": "book"}
]],
"safe labels": [[
{
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-bibtex/test/output/label.bib
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ @book{b
}
@book{b,
}
@book{123,
}
@book{0,
}
@book{undefined,
}
@book{null,
}

0 comments on commit 6291843

Please sign in to comment.