forked from omnivore-app/obsidian-omnivore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render highlight color in article note
perf: settings refactor
- Loading branch information
Showing
9 changed files
with
888 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.