From adb129da59d58fb4056472204976233dc55d4439 Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 28 Jun 2024 21:47:37 +0300 Subject: [PATCH] fix: new lines no longer break wrapped highlight blocks --- src/methods/aggregateDetails.ts | 14 +++++++++++--- test/mocks/aggregatedDetailsData.ts | 18 ++++++++++++++++++ test/mocks/renderedTemplate.ts | 26 ++++++++++++++++++++++++-- test/mocks/testDatabase.sqlite | Bin 737280 -> 737280 bytes 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/methods/aggregateDetails.ts b/src/methods/aggregateDetails.ts index 63a994a..09bb82d 100644 --- a/src/methods/aggregateDetails.ts +++ b/src/methods/aggregateDetails.ts @@ -25,11 +25,14 @@ export const aggregateBookAndHighlightDetails = async (): Promise { + const textForContext = annotation.ZANNOTATIONREPRESENTATIVETEXT; + const userNote = annotation.ZANNOTATIONNOTE; + return { chapter: annotation.ZFUTUREPROOFING5, - contextualText: annotation.ZANNOTATIONREPRESENTATIVETEXT, - highlight: annotation.ZANNOTATIONSELECTEDTEXT, - note: annotation.ZANNOTATIONNOTE, + contextualText: textForContext ? preserveNewlineIndentation(textForContext) : textForContext, + highlight: preserveNewlineIndentation(annotation.ZANNOTATIONSELECTEDTEXT), + note: userNote ? preserveNewlineIndentation(userNote) : userNote, highlightStyle: annotation.ZANNOTATIONSTYLE, highlightCreationDate: annotation.ZANNOTATIONCREATIONDATE, highlightModificationDate: annotation.ZANNOTATIONMODIFICATIONDATE @@ -43,3 +46,8 @@ export const aggregateBookAndHighlightDetails = async (): Promise { + return textBlock.includes('\n\n') ? textBlock.replace(/\n\n/g, '
\n') : textBlock; +} diff --git a/test/mocks/aggregatedDetailsData.ts b/test/mocks/aggregatedDetailsData.ts index 882cf07..05df178 100644 --- a/test/mocks/aggregatedDetailsData.ts +++ b/test/mocks/aggregatedDetailsData.ts @@ -18,6 +18,16 @@ export const annotationsToAggregate = [{ "ZANNOTATIONMODIFICATIONDATE": 731876693.002279, "ZANNOTATIONSTYLE": 3, "ZANNOTATIONDELETED": 0 +}, { + "ZANNOTATIONASSETID": "THBFYNJKTGFTTVCGSAE5", + "ZFUTUREPROOFING5": "Another aggregated Introduction", + "ZANNOTATIONREPRESENTATIVETEXT": "This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide\n\ncontaining a new line to test the preservation of indentation", + "ZANNOTATIONSELECTEDTEXT": "aggregated hightlight from the Apple iPhone User Guide\n\ncontaining a new line to test the preservation of indentation", + "ZANNOTATIONNOTE": "Test note for the aggregated hightlight from the Apple iPhone User Guide\n\nalong with a new line to test the preservation of indentation", + "ZANNOTATIONCREATIONDATE": 731876693.002279, + "ZANNOTATIONMODIFICATIONDATE": 731876693.002279, + "ZANNOTATIONSTYLE": 3, + "ZANNOTATIONDELETED": 0 }]; export const aggregatedHighlights = [{ @@ -36,5 +46,13 @@ export const aggregatedHighlights = [{ "highlightStyle": 3, "highlightCreationDate": 731876693.002279, "highlightModificationDate": 731876693.002279 + }, { + "chapter": "Another aggregated Introduction", + "contextualText": "This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide
\ncontaining a new line to test the preservation of indentation", + "highlight": "aggregated hightlight from the Apple iPhone User Guide
\ncontaining a new line to test the preservation of indentation", + "note": "Test note for the aggregated hightlight from the Apple iPhone User Guide
\nalong with a new line to test the preservation of indentation", + "highlightStyle": 3, + "highlightCreationDate": 731876693.002279, + "highlightModificationDate": 731876693.002279 }] }]; diff --git a/test/mocks/renderedTemplate.ts b/test/mocks/renderedTemplate.ts index adec8ee..85b2274 100644 --- a/test/mocks/renderedTemplate.ts +++ b/test/mocks/renderedTemplate.ts @@ -4,7 +4,7 @@ Link:: [Apple Books Link](ibooks://assetid/THBFYNJKTGFTTVCGSAE5) ## Annotations -Number of annotations:: 1 +Number of annotations:: 2 ---- @@ -13,6 +13,16 @@ Number of annotations:: 1 - 🎯 Highlight:: aggregated hightlight from the Apple iPhone User Guide - 📝 Note:: Test note for the aggregated hightlight from the Apple iPhone User Guide +---- + +- 📖 Chapter:: Another aggregated Introduction +- 🔖 Context:: This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide
+containing a new line to test the preservation of indentation +- 🎯 Highlight:: aggregated hightlight from the Apple iPhone User Guide
+containing a new line to test the preservation of indentation +- 📝 Note:: Test note for the aggregated hightlight from the Apple iPhone User Guide
+along with a new line to test the preservation of indentation + `; export const renderedCustomTemplateMock = `Title:: 📕 Apple iPhone - User Guide - Instructions - with - restricted - symbols - in - title @@ -26,7 +36,7 @@ Link:: [Apple Books Link](ibooks://assetid/THBFYNJKTGFTTVCGSAE5) ## Annotations -Number of annotations:: 1 +Number of annotations:: 2 ---- @@ -37,4 +47,16 @@ Number of annotations:: 1 - 📅 Highlight taken on:: 2024-03-11 03:04:53 PM -04:00 - 📅 Highlight modified on:: 2024-03-11 03:04:53 PM -04:00 +---- + +- 📖 Chapter:: Another aggregated Introduction +- 🔖 Context:: This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide
+containing a new line to test the preservation of indentation +- 🎯 Highlight:: aggregated hightlight from the Apple iPhone User Guide
+containing a new line to test the preservation of indentation
+- 📝 Note:: Test note for the aggregated hightlight from the Apple iPhone User Guide
+along with a new line to test the preservation of indentation +- 📅 Highlight taken on:: 2024-03-11 03:04:53 PM -04:00 +- 📅 Highlight modified on:: 2024-03-11 03:04:53 PM -04:00 + `; diff --git a/test/mocks/testDatabase.sqlite b/test/mocks/testDatabase.sqlite index c7cfef2e597e34d6535290201d71e0bad9569474..5d4603874b85f75fa9cc6227b2c5f02e9cae0c49 100644 GIT binary patch delta 2089 zcmW;L*LM|=}F47~+1)aX`rW0tKhE_(9H zpTN840FOTM2khD1@0*-6zq!Nr+n2i8y28F_X@V;Zo+Z7Gq5$c3p#Qup^*Cuj?dZQgzQr|F?$tG z${vT4vz>5Cb{U+Sod(}!&2U=gA)KCZ!x@>waAsx`oHdYHh|^b@NpN;X55@FdI46Ap z&Q0%w^U`bK{PbMdo_4?msh4nJ>IPhtIt>@6cETkoCtRAE1(&64up{{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