From 7b4f48319d193bbc53911a2b8f067aca81099405 Mon Sep 17 00:00:00 2001 From: Myllaume Date: Fri, 4 Oct 2024 11:51:46 +0200 Subject: [PATCH] fix: no convert quote if unknown id --- core/utils/convertQuotes.js | 6 ++++-- core/utils/convertQuotes.spec.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) 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.', + ); + }); });