Skip to content

Commit

Permalink
fix: no convert quote if unknown id
Browse files Browse the repository at this point in the history
  • Loading branch information
Myllaume committed Oct 4, 2024
1 parent ab678ce commit 7b4f483
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/utils/convertQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ function convertQuotes(markdown, bibliography, records, idToHighlight) {

const idsDictionnary = new Map();

for (const item of quote.citations) {
if (!bibliography.library[item.id]) continue;
if (!quote.citations.every(({ id }) => !!bibliography.library[id])) {
return markdown;
}

for (const item of quote.citations) {
// get text to replace for each quote item
const itemText = bibliography.citeproc
.processCitationCluster(
Expand Down
16 changes: 16 additions & 0 deletions core/utils/convertQuotes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ describe('convertQuotes', () => {
);
});

it('should convert no link', () => {
const text = 'Lorem ipsum dolor est.';

const result = convertQuotes(text, bibliography, records, 'matuschak2019');

expect(result).toEqual('Lorem ipsum dolor est.');
});

it('should not add "highlight" class if unknown record', () => {
const text = 'Lorem @matuschak2019 ipsum dolor est.';

Expand All @@ -150,4 +158,12 @@ describe('convertQuotes', () => {
'Lorem (Matuschak, 2019) ipsum dolor est.',
);
});

it('should return original if unknown quote id from library', () => {
const text = 'Lorem [@matuschak2019; @unknown] ipsum dolor est.';

expect(convertQuotes(text, bibliography, records, 'matuschak2019')).toEqual(
'Lorem [@matuschak2019; @unknown] ipsum dolor est.',
);
});
});

0 comments on commit 7b4f483

Please sign in to comment.