Skip to content

Commit

Permalink
Merge pull request #94 from omnivore-app/fix/multi-paragraph
Browse files Browse the repository at this point in the history
fix: replace all empty lines with blockquote ">" to preserve paragraphs
  • Loading branch information
sywhb authored Apr 13, 2023
2 parents 39c33ce + cfcb32e commit 8aab129
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/settings/template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Mustache from 'mustache'
import { Article, Highlight, HighlightType, Label, PageType } from '../api'
import { dateReference, formatDate, siteNameFromUrl } from '../util'
import {
dateReference,
formatDate,
formatHighlightQuote,
siteNameFromUrl,
} from '../util'

export interface ArticleVariables {
title: string
Expand Down Expand Up @@ -107,7 +112,7 @@ export const renderHighlightContent = (
const articleVariables = buildArticleVariables(article, preferredDateFormat)
const highlightVariables: TemplateVariables = {
...articleVariables,
text: highlight.quote,
text: formatHighlightQuote(highlight.quote, template),
labels: highlight.labels,
highlightUrl: `https://omnivore.app/me/${article.slug}#${highlight.id}`,
dateHighlighted,
Expand Down
12 changes: 12 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ export const siteNameFromUrl = (originalArticleUrl: string): string => {
}

export const delay = (t = 100) => new Promise((r) => setTimeout(r, t))

export const formatHighlightQuote = (
quote: string,
template: string
): string => {
if (template.startsWith('>')) {
// replace all empty lines with blockquote '>' to preserve paragraphs
quote = quote.replace(/^(?=\n)$|^\s*?\n/gm, '> ')
}

return quote
}

0 comments on commit 8aab129

Please sign in to comment.