Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: render highlight color in article note (#215) #220

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading