Skip to content

Commit

Permalink
test: add test for shiki dual themes (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Sep 4, 2024
1 parent 4f48c49 commit e487bbf
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
- uses: googleapis/release-please-action@v4
id: release-please
with:
release-type: node
Expand Down
13 changes: 9 additions & 4 deletions playground/shiki-lazy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHighlightPlugin } from 'prosemirror-highlight'
import { createParser, type Parser } from 'prosemirror-highlight/shiki'
import {
getSingletonHighlighter,
createHighlighter,
type BuiltinLanguage,
type Highlighter,
} from 'shiki'
Expand All @@ -18,8 +18,8 @@ let parser: Parser | undefined
*/
const lazyParser: Parser = (options) => {
if (!highlighter) {
return getSingletonHighlighter({
themes: ['github-light'],
return createHighlighter({
themes: ['github-light', 'github-dark'],
langs: [],
}).then((h) => {
highlighter = h
Expand All @@ -32,7 +32,12 @@ const lazyParser: Parser = (options) => {
}

if (!parser) {
parser = createParser(highlighter)
parser = createParser(highlighter, {
themes: {
light: 'github-light',
dark: 'github-dark',
},
})
}

return parser(options)
Expand Down
130 changes: 130 additions & 0 deletions test/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,134 @@ describe('createHighlightPlugin', () => {
`,
)
})

it('can highlight code blocks with shiki', async () => {
const { createParser } = await import('../src/shiki')
const { createHighlighter } = await import('shiki')

const highlighter = await createHighlighter({
themes: ['github-light', 'github-dark', 'github-dark-dimmed'],
langs: ['typescript', 'python'],
})

const parser = createParser(highlighter, {
themes: {
light: 'github-light',
dark: 'github-dark',
dim: 'github-dark-dimmed',
},
defaultColor: false,
})
const plugin = createHighlightPlugin({ parser })

const state = EditorState.create({ doc, plugins: [plugin] })
const view = new EditorView(document.createElement('div'), { state })

const html = await formatHtml(view.dom.outerHTML)
expect(html).toMatchInlineSnapshot(
`
"<div contenteditable="true" translate="no" class="ProseMirror">
<pre data-language="typescript">
<code>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
console.
</span>
<span
class="shiki"
style="--shiki-light: #6F42C1; --shiki-dark: #B392F0; --shiki-dim: #DCBDFB;"
>
log
</span>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
(
</span>
<span
class="shiki"
style="--shiki-light: #005CC5; --shiki-dark: #79B8FF; --shiki-dim: #6CB6FF;"
>
123
</span>
<span
class="shiki"
style="--shiki-light: #D73A49; --shiki-dark: #F97583; --shiki-dim: #F47067;"
>
+
</span>
<span
class="shiki"
style="--shiki-light: #032F62; --shiki-dark: #9ECBFF; --shiki-dim: #96D0FF;"
>
"456"
</span>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
);
</span>
</code>
</pre>
<pre data-language="python">
<code>
<span
class="shiki"
style="--shiki-light: #005CC5; --shiki-dark: #79B8FF; --shiki-dim: #6CB6FF;"
>
print
</span>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
(
</span>
<span
class="shiki"
style="--shiki-light: #032F62; --shiki-dark: #9ECBFF; --shiki-dim: #96D0FF;"
>
"1+1"
</span>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
,
</span>
<span
class="shiki"
style="--shiki-light: #032F62; --shiki-dark: #9ECBFF; --shiki-dim: #96D0FF;"
>
"="
</span>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
,
</span>
<span
class="shiki"
style="--shiki-light: #005CC5; --shiki-dark: #79B8FF; --shiki-dim: #6CB6FF;"
>
2
</span>
<span
class="shiki"
style="--shiki-light: #24292E; --shiki-dark: #E1E4E8; --shiki-dim: #ADBAC7;"
>
)
</span>
</code>
</pre>
</div>;
"
`,
)
})
})

0 comments on commit e487bbf

Please sign in to comment.