Skip to content

Commit

Permalink
🔭 Trim spaces in bibtex URLs and DOIs (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Aug 8, 2024
1 parent 134598f commit 1ac4d7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-forks-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"citation-js-utils": patch
---

Trim spaces on DOIs and URLs in bibtex
17 changes: 17 additions & 0 deletions packages/citation-js-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type CSL = {
'container-title'?: string;
abstract?: string;
DOI?: string;
URL?: string;
ISBN?: string;
ISSN?: string;
issue?: string;
Expand Down Expand Up @@ -264,6 +265,22 @@ export function getCitationRenderers(data: CSL[]): CitationRenderer {
if (!c.id) {
c.id = formatLabel(c);
}
// Trim the titles, DOIs, etc. on load
[
'title',
'note',
'publisher',
'page',
'volume',
'issue',
'container-title',
'DOI',
'ISSN',
].forEach((tag) => {
if (c[tag]) c[tag] = c[tag].trim();
});
// Trim the DOIs and URLs (these are encoded) on load
if (c.URL) c.URL = c.URL.replace(/^(%20)*/, '').replace(/(%20)*$/, '');
return [
c.id,
{
Expand Down
24 changes: 12 additions & 12 deletions packages/citation-js-utils/tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
export const bibtex = `@article{Cockett2015SimPEG,
author = {Cockett, Rowan and Kang, Seogi and Heagy, Lindsey J. and Pidlisecky, Adam and Oldenburg, Douglas W.},
journal = {Computers & Geosciences},
year = {2015},
month = {12},
pages = {142--154},
title = {SimPEG: An open source framework for simulation and gradient based parameter estimation in geophysical applications},
volume = {85},
doi = {10.1016/j.cageo.2015.09.015},
issn = {0098-3004},
url = {http://dx.doi.org/10.1016/j.cageo.2015.09.015},
author = {Cockett, Rowan and Kang, Seogi and Heagy, Lindsey J. and Pidlisecky, Adam and Oldenburg, Douglas W. },
journal = {Computers & Geosciences },
year = { 2015},
month = {12 },
pages = { 142--154},
title = { SimPEG: An open source framework for simulation and gradient based parameter estimation in geophysical applications },
volume = { 85 },
doi = { 10.1016/j.cageo.2015.09.015 },
issn = {0098-3004 },
url = { http://dx.doi.org/10.1016/j.cageo.2015.09.015 },
}`;

export const doiInNote = `@article{cury2020sparse,
title={A sparse EEG-informed fMRI model for hybrid EEG-fMRI neurofeedback prediction},
author={Cury, Claire and Maurel, Pierre and Gribonval, R{\\'e}mi and Barillot, Christian},
journal={Frontiers in neuroscience},
note = {See the DOI in \\url{https://doi.org/10.3389/fnins.2019.01451}, for example.},
note = { See the DOI in \\url{https://doi.org/10.3389/fnins.2019.01451}, for example.},
volume={13},
pages={1451},
year={2020},
Expand All @@ -26,7 +26,7 @@ export const doiInURL = `@article{cury2020sparse,
title={A sparse EEG-informed fMRI model for hybrid EEG-fMRI neurofeedback prediction},
author={Cury, Claire and Maurel, Pierre and Gribonval, R{\\'e}mi and Barillot, Christian},
journal={Frontiers in neuroscience},
url = {https://doi.org/10.3389/fnins.2019.01451},
url = { https://doi.org/10.3389/fnins.2019.01451 },
volume={13},
pages={1451},
year={2020},
Expand Down

0 comments on commit 1ac4d7a

Please sign in to comment.