Skip to content

Commit

Permalink
fix: replace all empty lines with blockquote ">" to preserve paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Apr 13, 2023
1 parent 8141166 commit e02e5de
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/settings/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Article, HighlightType, PageType } from "../api";
import {
compareHighlightsInFile,
formatDate,
formatHighlightQuote,
getHighlightLocation,
siteNameFromUrl,
} from "../util";
Expand Down Expand Up @@ -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(" ", "_"),
}));
};

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
39 changes: 16 additions & 23 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit e02e5de

Please sign in to comment.