Skip to content

Commit

Permalink
🐛 Do not fail on citation.js (#1076)
Browse files Browse the repository at this point in the history
See #1072
  • Loading branch information
rowanc1 authored Apr 8, 2024
1 parent 770c15f commit 8ca2c51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-ligers-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-cli": patch
---

Do not error on invalid citation bibtex
23 changes: 18 additions & 5 deletions packages/myst-cli/src/transforms/dois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getCitations } from 'citation-js-utils';
import { doi } from 'doi-utils';
import type { Link } from 'myst-spec';
import type { GenericNode, GenericParent } from 'myst-common';
import { fileWarn, toText, RuleId, plural } from 'myst-common';
import { fileWarn, toText, RuleId, plural, fileError } from 'myst-common';
import { selectAll } from 'unist-util-select';
import { computeHash, tic } from 'myst-cli-utils';
import type { Cite } from 'myst-spec-ext';
Expand Down Expand Up @@ -118,10 +118,23 @@ export async function getCitation(
});
return null;
}
const renderer = await getCitations(bibtex);
const id = Object.keys(renderer)[0];
const render = renderer[id];
return { id, render };
try {
const renderer = await getCitations(bibtex);
const id = Object.keys(renderer)[0];
const render = renderer[id];
return { id, render };
} catch (error) {
fileError(
vfile,
`BibTeX from doi.org was malformed, please edit and add to your local references`,
{
node,
ruleId: RuleId.doiLinkValid,
note: `\nBibTeX from ${doiString}:\n\n${bibtex}\n`,
},
);
return null;
}
}

/**
Expand Down

0 comments on commit 8ca2c51

Please sign in to comment.