Skip to content

Commit

Permalink
feat: render highlight color in article note
Browse files Browse the repository at this point in the history
perf: settings refactor
  • Loading branch information
sywhb committed Apr 17, 2024
2 parents 2aea5e1 + 0922ffc commit c8a4e70
Show file tree
Hide file tree
Showing 9 changed files with 888 additions and 488 deletions.
109 changes: 109 additions & 0 deletions src/__tests__/renderHighlightColorQuote.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { HighlightRenderOption, formatHighlightQuote } from '../util'
import { HighlightManagerId } from '../settings'

type testCase = {
quote: string
template: string
highlightRenderOption: HighlightRenderOption | null
expected: string
}

const quote = 'some quote'
const color = 'red'
const templateWithoutBlockQuote = `{{#highlights}}
{{{text}}}
{{/highlights}}`
const templateWithBlockQuote = `{{#highlights}}
> {{{text}}}
{{/highlights}}`

const blockQuoteNoHighlightRenderOption = {
quote: quote,
template: templateWithBlockQuote,
highlightRenderOption: null,
expected: quote,
}

const noBlockQuoteNoHighlightRenderOption = {
quote: quote,
template: templateWithoutBlockQuote,
highlightRenderOption: null,
expected: quote,
}

const blockQuoteOmnivoreRenderOption = {
quote: quote,
template: templateWithBlockQuote,
highlightRenderOption: {
highlightManagerId: HighlightManagerId.OMNIVORE,
highlightColor: color,
},
expected: `<mark class="${HighlightManagerId.OMNIVORE} ${HighlightManagerId.OMNIVORE}-${color}">${quote}</mark>`,
}

const blockQuoteMultiLineOmnivoreRenderOption = {
quote: `${quote}
${quote}`,
template: templateWithBlockQuote,
highlightRenderOption: {
highlightManagerId: HighlightManagerId.OMNIVORE,
highlightColor: color,
},
expected: `<mark class="${HighlightManagerId.OMNIVORE} ${HighlightManagerId.OMNIVORE}-${color}">${quote}</mark>
><mark class="${HighlightManagerId.OMNIVORE} ${HighlightManagerId.OMNIVORE}-${color}"> ${quote}</mark>`,
}

const blockQuoteHighlightrRenderOption = {
quote: quote,
template: templateWithBlockQuote,
highlightRenderOption: {
highlightManagerId: HighlightManagerId.HIGHLIGHTR,
highlightColor: color,
},
expected: `<mark class="${HighlightManagerId.HIGHLIGHTR}-${color}">${quote}</mark>`,
}

const noBlockQuoteMultiLineOmnivoreRenderOption = {
quote: `${quote}
${quote}`,
template: templateWithoutBlockQuote,
highlightRenderOption: {
highlightManagerId: HighlightManagerId.OMNIVORE,
highlightColor: color,
},
expected: `<mark class="${HighlightManagerId.OMNIVORE} ${HighlightManagerId.OMNIVORE}-${color}">${quote}</mark>
<mark class="${HighlightManagerId.OMNIVORE} ${HighlightManagerId.OMNIVORE}-${color}">${quote}</mark>`,
}

const blockQuoteEmptyLineOmnivoreRenderOption = {
quote: `${quote}
`,
template: templateWithBlockQuote,
highlightRenderOption: {
highlightManagerId: HighlightManagerId.OMNIVORE,
highlightColor: color,
},
expected: `<mark class="${HighlightManagerId.OMNIVORE} ${HighlightManagerId.OMNIVORE}-${color}">${quote}</mark>
>`,
}

const testCases: testCase[] = [
blockQuoteNoHighlightRenderOption,
noBlockQuoteNoHighlightRenderOption,
blockQuoteOmnivoreRenderOption,
blockQuoteMultiLineOmnivoreRenderOption,
blockQuoteHighlightrRenderOption,
noBlockQuoteMultiLineOmnivoreRenderOption,
blockQuoteEmptyLineOmnivoreRenderOption,
]

describe('formatHighlightQuote', () => {
test.each(testCases)('should correctly for format %s', (testCase) => {
const result = formatHighlightQuote(
testCase.quote,
testCase.template,
testCase.highlightRenderOption,
)
expect(result).toBe(testCase.expected)
})
})
7 changes: 7 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Item, ItemFormat, Omnivore } from '@omnivore-app/api'

export enum HighlightColors {
Yellow = 'yellow',
Red = 'red',
Green = 'green',
Blue = 'blue',
}

export const getItems = async (
endpoint: string,
apiKey: string,
Expand Down
Loading

0 comments on commit c8a4e70

Please sign in to comment.