diff --git a/core/utils/convertQuotes.js b/core/utils/convertQuotes.js index 59a54831..8e8d258e 100644 --- a/core/utils/convertQuotes.js +++ b/core/utils/convertQuotes.js @@ -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( diff --git a/core/utils/convertQuotes.spec.js b/core/utils/convertQuotes.spec.js index c8d6df27..34b36408 100644 --- a/core/utils/convertQuotes.spec.js +++ b/core/utils/convertQuotes.spec.js @@ -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.'; @@ -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.', + ); + }); });