diff --git a/src/settings/template.ts b/src/settings/template.ts index 42f7f1f..5b58e51 100644 --- a/src/settings/template.ts +++ b/src/settings/template.ts @@ -5,6 +5,7 @@ import { Article, HighlightType, PageType } from "../api"; import { compareHighlightsInFile, formatDate, + formatHighlightQuote, getHighlightLocation, siteNameFromUrl, } from "../util"; @@ -103,7 +104,7 @@ export const renderAttachmentFolder = ( export const renderLabels = (labels?: LabelVariable[]) => { return labels?.map((l) => ({ // replace spaces with underscores because Obsidian doesn't allow spaces in tags - name: l.name.replace(" ", "_"), + name: l.name.replaceAll(" ", "_"), })); }; @@ -144,7 +145,7 @@ export const renderArticleContnet = async ( const highlights: HighlightVariables[] = articleHighlights.map( (highlight) => { return { - text: highlight.quote, + text: formatHighlightQuote(highlight.quote, template), highlightUrl: `https://omnivore.app/me/${article.slug}#${highlight.id}`, dateHighlighted: formatDate(highlight.updatedAt, dateHighlightedFormat), note: highlight.annotation, diff --git a/src/util.ts b/src/util.ts index c9e4ea1..82f7407 100644 --- a/src/util.ts +++ b/src/util.ts @@ -120,3 +120,17 @@ export const siteNameFromUrl = (originalArticleUrl: string): string => { return ""; } }; + +export const formatHighlightQuote = ( + quote: string, + template: string +): string => { + // if the template has highlights, we need to preserve paragraphs + const regex = /{{#highlights}}(\n)*>/gm; + if (regex.test(template)) { + // replace all empty lines with blockquote '>' to preserve paragraphs + quote = quote.replaceAll(">", ">").replaceAll(/\n/gm, "\n> "); + } + + return quote; +}; diff --git a/tsconfig.json b/tsconfig.json index 29d45d9..0a19b42 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,18 @@ { - "compilerOptions": { - "baseUrl": ".", - "inlineSourceMap": true, - "inlineSources": true, - "module": "ESNext", - "target": "ES6", - "allowJs": true, - "noImplicitAny": true, - "moduleResolution": "node", - "importHelpers": true, - "isolatedModules": true, - "strictNullChecks": true, - "esModuleInterop": true, - "lib": [ - "DOM", - "ES5", - "ES6", - "ES7" - ] - }, - "include": [ - "**/*.ts" - ] + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "target": "ES2021", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "isolatedModules": true, + "strictNullChecks": true, + "esModuleInterop": true, + "lib": ["ES2021", "DOM"] + }, + "include": ["**/*.ts"] }