Skip to content

Commit

Permalink
feature: render highlight color in article note
Browse files Browse the repository at this point in the history
improvement: settings refactor
  • Loading branch information
aaachen committed Apr 10, 2024
1 parent 8e26056 commit b533f6f
Show file tree
Hide file tree
Showing 8 changed files with 863 additions and 483 deletions.
107 changes: 107 additions & 0 deletions src/__tests__/renderHighlightColorQuote.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { HighlightRenderOption, formatHighlightQuote } from '../util'
import { DEFAULT_SETTINGS, HighlightManagerId } from '../settings'

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 19.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 19.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 16.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 14.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 14.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 19.x)

'DEFAULT_SETTINGS' is defined but never used

Check failure on line 2 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 16.x)

'DEFAULT_SETTINGS' is defined but never used

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>`,
}


Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 19.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 19.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 16.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 14.x)

Delete `␍⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 14.x)

Delete `⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Delete `␍⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 19.x)

Delete `␍⏎`

Check failure on line 56 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 16.x)

Delete `␍⏎`
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>
>`,
}


Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 19.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 19.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 16.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 14.x)

Delete `␍⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 14.x)

Delete `⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Delete `␍⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 19.x)

Delete `␍⏎`

Check failure on line 91 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 16.x)

Delete `␍⏎`
const testCases: testCase[] = [
blockQuoteNoHighlightRenderOption,
noBlockQuoteNoHighlightRenderOption,
blockQuoteOmnivoreRenderOption,
blockQuoteMultiLineOmnivoreRenderOption,
blockQuoteHighlightrRenderOption,
noBlockQuoteMultiLineOmnivoreRenderOption,
blockQuoteEmptyLineOmnivoreRenderOption

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 19.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 19.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 16.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 14.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 14.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 19.x)

Insert `,`

Check failure on line 99 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 16.x)

Insert `,`
]

describe('formatHighlightQuote', () => {
test.each(testCases)('should correctly for format %s', (testCase) => {
const result = formatHighlightQuote(testCase.quote, testCase.template, testCase.highlightRenderOption)

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 14.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 19.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 19.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 16.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 14.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `␍⏎······testCase.quote,␍⏎······testCase.template,␍⏎······testCase.highlightRenderOption,␍⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 14.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `⏎······testCase.quote,⏎······testCase.template,⏎······testCase.highlightRenderOption,⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `␍⏎······testCase.quote,␍⏎······testCase.template,␍⏎······testCase.highlightRenderOption,␍⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 19.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `␍⏎······testCase.quote,␍⏎······testCase.template,␍⏎······testCase.highlightRenderOption,␍⏎····`

Check failure on line 104 in src/__tests__/renderHighlightColorQuote.spec.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest, 16.x)

Replace `testCase.quote,·testCase.template,·testCase.highlightRenderOption` with `␍⏎······testCase.quote,␍⏎······testCase.template,␍⏎······testCase.highlightRenderOption,␍⏎····`
expect(result).toBe(testCase.expected)
})
})
8 changes: 8 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export interface Highlight {
highlightPositionAnchorIndex: number
}

// Highlight colors currently supported in Omnivore
export enum HighlightColors {
Yellow = 'yellow',
Red = 'red',
Green = 'green',
Blue = 'blue',
}

const requestHeaders = (apiKey: string) => ({
'Content-Type': 'application/json',
authorization: apiKey,
Expand Down
Loading

0 comments on commit b533f6f

Please sign in to comment.