Skip to content

Commit

Permalink
fix: new lines no longer break wrapped highlight blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bandantonio committed Jun 28, 2024
1 parent 3459e8c commit a09ec8c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/methods/aggregateDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const aggregateBookAndHighlightDetails = async (): Promise<ICombinedBooks
annotations: bookRelatedAnnotations.map(annotation => {
return {
chapter: annotation.ZFUTUREPROOFING5,
contextualText: annotation.ZANNOTATIONREPRESENTATIVETEXT,
highlight: annotation.ZANNOTATIONSELECTEDTEXT,
note: annotation.ZANNOTATIONNOTE,
contextualText: preserveNewlineIndentation(annotation.ZANNOTATIONREPRESENTATIVETEXT),
highlight: preserveNewlineIndentation(annotation.ZANNOTATIONSELECTEDTEXT),
note: preserveNewlineIndentation(annotation.ZANNOTATIONNOTE),
highlightStyle: annotation.ZANNOTATIONSTYLE,
highlightCreationDate: annotation.ZANNOTATIONCREATIONDATE,
highlightModificationDate: annotation.ZANNOTATIONMODIFICATIONDATE
Expand All @@ -43,3 +43,8 @@ export const aggregateBookAndHighlightDetails = async (): Promise<ICombinedBooks

return resultingHighlights;
};

// Handler of double new line characters (\n\n) to preserve proper indentation in text blocks
const preserveNewlineIndentation = (text: string): string => {
return text.replace(/\n\n/g, '<br>\n');
}
18 changes: 18 additions & 0 deletions test/mocks/aggregatedDetailsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{
Expand All @@ -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<br>\ncontaining a new line to test the preservation of indentation",
"highlight": "aggregated hightlight from the Apple iPhone User Guide<br>\ncontaining a new line to test the preservation of indentation",
"note": "Test note for the aggregated hightlight from the Apple iPhone User Guide<br>\nalong with a new line to test the preservation of indentation",
"highlightStyle": 3,
"highlightCreationDate": 731876693.002279,
"highlightModificationDate": 731876693.002279
}]
}];
26 changes: 24 additions & 2 deletions test/mocks/renderedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Link:: [Apple Books Link](ibooks://assetid/THBFYNJKTGFTTVCGSAE5)
## Annotations
Number of annotations:: 1
Number of annotations:: 2
----
Expand All @@ -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<br>
containing a new line to test the preservation of indentation
- 🎯 Highlight:: aggregated hightlight from the Apple iPhone User Guide<br>
containing a new line to test the preservation of indentation
- 📝 Note:: Test note for the aggregated hightlight from the Apple iPhone User Guide<br>
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
Expand All @@ -26,7 +36,7 @@ Link:: [Apple Books Link](ibooks://assetid/THBFYNJKTGFTTVCGSAE5)
## Annotations
Number of annotations:: 1
Number of annotations:: 2
----
Expand All @@ -37,4 +47,16 @@ Number of annotations:: 1
- <small>📅 Highlight taken on:: 2024-03-11 03:04:53 PM -04:00</small>
- <small>📅 Highlight modified on:: 2024-03-11 03:04:53 PM -04:00</small>
----
- 📖 Chapter:: Another aggregated Introduction
- 🔖 Context:: This is a contextual text for the aggregated hightlight from the Apple iPhone User Guide<br>
containing a new line to test the preservation of indentation
- 🎯 Highlight:: <mark style="background:rgb(249,213,108); color:#000; padding:2px;">aggregated hightlight from the Apple iPhone User Guide<br>
containing a new line to test the preservation of indentation</mark>
- 📝 Note:: Test note for the aggregated hightlight from the Apple iPhone User Guide<br>
along with a new line to test the preservation of indentation
- <small>📅 Highlight taken on:: 2024-03-11 03:04:53 PM -04:00</small>
- <small>📅 Highlight modified on:: 2024-03-11 03:04:53 PM -04:00</small>
`;
Binary file modified test/mocks/testDatabase.sqlite
Binary file not shown.

0 comments on commit a09ec8c

Please sign in to comment.