Skip to content

Commit 1ad8480

Browse files
danielroefarnabaz
andauthored
fix(highlight): accept bundled theme names in themes option (#308)
Co-authored-by: Farnabaz <farnabaz@gmail.com>
1 parent b6cec25 commit 1ad8480

18 files changed

Lines changed: 188 additions & 169 deletions

File tree

.github/workflows/commit-signature.yml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,41 @@ jobs:
8080
)
8181
.join('\n')
8282
83-
const body = `${marker}
84-
## ✍️ Unsigned commit(s) detected
85-
86-
@${author} one or more commits on this PR are **not signed**. Please sign them and update the PR.
87-
88-
### Unsigned commits
89-
90-
${list}
91-
92-
### How to fix
93-
94-
Sign your commits with GPG or SSH, then force-push the updated history:
95-
96-
\`\`\`bash
97-
# Configure signing once (GPG example)
98-
git config --global commit.gpgsign true
99-
# or SSH: git config --global gpg.format ssh && git config --global user.signingkey ~/.ssh/id_ed25519.pub
100-
101-
# Re-sign all commits on this branch (from the merge base)
102-
git rebase --exec 'git commit --amend --no-edit -S' ${baseSha}
103-
104-
# Push the rewritten history
105-
git push --force-with-lease
106-
\`\`\`
107-
108-
If you only need to re-sign the tip commit:
109-
110-
\`\`\`bash
111-
git commit --amend --no-edit -S
112-
git push --force-with-lease
113-
\`\`\`
114-
115-
See GitHub’s guide: [About commit signature verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification).
116-
`
83+
const body = [
84+
marker,
85+
'## ✍️ Unsigned commit(s) detected',
86+
'',
87+
`@${author} one or more commits on this PR are **not signed**. Please sign them and update the PR.`,
88+
'',
89+
'### Unsigned commits',
90+
'',
91+
list,
92+
'',
93+
'### How to fix',
94+
'',
95+
'Sign your commits with GPG or SSH, then force-push the updated history:',
96+
'',
97+
'```bash',
98+
'# Configure signing once (GPG example)',
99+
'git config --global commit.gpgsign true',
100+
'# or SSH: git config --global gpg.format ssh && git config --global user.signingkey ~/.ssh/id_ed25519.pub',
101+
'',
102+
'# Re-sign all commits on this branch (from the merge base)',
103+
`git rebase --exec 'git commit --amend --no-edit -S' ${baseSha}`,
104+
'',
105+
'# Push the rewritten history',
106+
'git push --force-with-lease',
107+
'```',
108+
'',
109+
'If you only need to re-sign the tip commit:',
110+
'',
111+
'```bash',
112+
'git commit --amend --no-edit -S',
113+
'git push --force-with-lease',
114+
'```',
115+
'',
116+
'See GitHub\'s guide: [About commit signature verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification).',
117+
].join('\n')
117118
118119
if (existing) {
119120
await github.rest.issues.updateComment({

docs/content/3.rendering/2.html.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ See [ComarkPlugin](/plugins) for available plugins.
8888
```typescript [render.ts]
8989
import { render } from '@comark/html'
9090
import highlight from '@comark/html/plugins/highlight'
91-
import githubLight from '@shikijs/themes/github-light'
92-
import githubDark from '@shikijs/themes/github-dark'
9391

9492
const html = await render('```js\nconsole.log("hi")\n```', {
9593
plugins: [
9694
highlight({
97-
themes: { light: githubLight, dark: githubDark }
95+
themes: { light: 'github-light', dark: 'github-dark' }
9896
})
9997
],
10098
})

docs/content/3.rendering/3.vue.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,12 @@ See [ComarkPlugin](/plugins) for available plugins.
129129
<script setup lang="ts">
130130
import { Comark } from '@comark/vue'
131131
import highlight from '@comark/vue/plugins/highlight'
132-
import githubLight from '@shikijs/themes/github-light'
133-
import githubDark from '@shikijs/themes/github-dark'
134132
135133
const plugins = [
136134
highlight({
137135
themes: {
138-
light: githubLight,
139-
dark: githubDark
136+
light: 'github-light',
137+
dark: 'github-dark'
140138
}
141139
})
142140
]
@@ -282,8 +280,6 @@ import { defineComarkComponent } from '@comark/vue'
282280
import highlight from '@comark/vue/plugins/highlight'
283281
import math, { Math } from '@comark/vue/plugins/math'
284282
import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid'
285-
import githubLight from '@shikijs/themes/github-light'
286-
import githubDark from '@shikijs/themes/github-dark'
287283
import CustomAlert from './components/CustomAlert.vue'
288284

289285
export const AppComark = defineComarkComponent({
@@ -294,8 +290,8 @@ export const AppComark = defineComarkComponent({
294290
mermaid(),
295291
highlight({
296292
themes: {
297-
light: githubLight,
298-
dark: githubDark
293+
light: 'github-light',
294+
dark: 'github-dark'
299295
},
300296
}),
301297
],
@@ -347,8 +343,6 @@ Inherit plugins and components from another component, then layer your own on to
347343
```typescript [comark.ts]
348344
import { defineComarkComponent } from '@comark/vue'
349345
import highlight from '@comark/vue/plugins/highlight'
350-
import githubLight from '@shikijs/themes/github-light'
351-
import githubDark from '@shikijs/themes/github-dark'
352346
import toc from '@comark/vue/plugins/toc'
353347
import math, { Math } from '@comark/vue/plugins/math'
354348
import ProsePre from './components/ProsePre.vue'
@@ -357,7 +351,7 @@ import ProsePre from './components/ProsePre.vue'
357351
export const BaseComark = defineComarkComponent({
358352
name: 'BaseComark',
359353
plugins: [
360-
highlight({ themes: { light: githubLight, dark: githubDark } }),
354+
highlight({ themes: { light: 'github-light', dark: 'github-dark' } }),
361355
],
362356
components: { ProsePre },
363357
})

docs/content/3.rendering/4.nuxt.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ See [ComarkPlugin](/plugins) for available plugins.
125125
```vue [app.vue]
126126
<script setup lang="ts">
127127
import highlight from '@comark/nuxt/plugins/highlight'
128-
import githubLight from '@shikijs/themes/github-light'
129-
import githubDark from '@shikijs/themes/github-dark'
130128
131129
const plugins = [
132130
highlight({
133-
themes: { light: githubLight, dark: githubDark }
131+
themes: { light: 'github-light', dark: 'github-dark' }
134132
})
135133
]
136134
</script>

docs/content/3.rendering/5.react.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ See [ComarkPlugin](/plugins) for available plugins.
111111
```tsx [App.tsx]
112112
import { Comark } from '@comark/react'
113113
import highlight from '@comark/react/plugins/highlight'
114-
import githubLight from '@shikijs/themes/github-light'
115-
import githubDark from '@shikijs/themes/github-dark'
116114

117115
const plugins = [
118116
highlight({
119-
themes: { light: githubLight, dark: githubDark }
117+
themes: { light: 'github-light', dark: 'github-dark' }
120118
})
121119
]
122120

@@ -241,8 +239,6 @@ import { defineComarkComponent } from '@comark/react'
241239
import highlight from '@comark/react/plugins/highlight'
242240
import math, { Math } from '@comark/react/plugins/math'
243241
import mermaid, { Mermaid } from '@comark/react/plugins/mermaid'
244-
import githubLight from '@shikijs/themes/github-light'
245-
import githubDark from '@shikijs/themes/github-dark'
246242
import CustomAlert from './components/CustomAlert'
247243

248244
export const AppComark = defineComarkComponent({
@@ -253,8 +249,8 @@ export const AppComark = defineComarkComponent({
253249
mermaid(),
254250
highlight({
255251
themes: {
256-
light: githubLight,
257-
dark: githubDark
252+
light: 'github-light',
253+
dark: 'github-dark'
258254
},
259255
}),
260256
],
@@ -310,16 +306,14 @@ Inherit plugins and components from another component, then layer your own on to
310306
```typescript [comark/index.ts]
311307
import { defineComarkComponent } from '@comark/react'
312308
import highlight from '@comark/react/plugins/highlight'
313-
import githubLight from '@shikijs/themes/github-light'
314-
import githubDark from '@shikijs/themes/github-dark'
315309
import toc from '@comark/react/plugins/toc'
316310
import math, { Math } from '@comark/react/plugins/math'
317311
import CodeBlock from './components/CodeBlock'
318312

319313
// Base: highlight + shared prose overrides, used everywhere
320314
const BaseComark = defineComarkComponent({
321315
name: 'BaseComark',
322-
plugins: [highlight({ themes: { light: githubLight, dark: githubDark } })],
316+
plugins: [highlight({ themes: { light: 'github-light', dark: 'github-dark' } })],
323317
components: { pre: CodeBlock },
324318
})
325319

docs/content/3.rendering/6.svelte.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ See [ComarkPlugin](/plugins) for available plugins.
9393
<script lang="ts">
9494
import { Comark } from '@comark/svelte'
9595
import highlight from '@comark/svelte/plugins/highlight'
96-
import githubLight from '@shikijs/themes/github-light'
9796
9897
const plugins = [
99-
highlight({ theme: githubLight }),
98+
highlight({
99+
themes: { light: 'github-light', dark: 'github-dark' },
100+
}),
100101
]
101102
</script>
102103

docs/content/3.rendering/7.angular.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ See [ComarkPlugin](/plugins) for available plugins.
106106
import { Component } from '@angular/core'
107107
import { ComarkComponent } from '@comark/angular'
108108
import highlight from '@comark/angular/plugins/highlight'
109-
import githubLight from '@shikijs/themes/github-light'
110-
import githubDark from '@shikijs/themes/github-dark'
111109

112110
@Component({
113111
selector: 'app-root',
@@ -119,7 +117,7 @@ export class AppComponent {
119117
content = '```js\nconsole.log("hello")\n```'
120118
plugins = [
121119
highlight({
122-
themes: { light: githubLight, dark: githubDark },
120+
themes: { light: 'github-light', dark: 'github-dark' },
123121
}),
124122
]
125123
}

docs/content/4.plugins/1.built-in/syntax-highlight.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,18 @@ npm install shiki
2828

2929
## Usage
3030

31-
Import themes from `@shikijs/themes` for type safety and tree-shaking:
31+
Pass [bundled theme names](https://shiki.style/themes) as strings — no extra imports needed:
3232

3333
```typescript
3434
import { parse } from 'comark'
3535
import highlight from 'comark/plugins/highlight'
36-
import githubLight from '@shikijs/themes/github-light'
37-
import githubDark from '@shikijs/themes/github-dark'
3836

3937
const result = await parse(content, {
4038
plugins: [
4139
highlight({
4240
themes: {
43-
light: githubLight,
44-
dark: githubDark
41+
light: 'github-light',
42+
dark: 'github-dark'
4543
}
4644
})
4745
]
@@ -56,12 +54,10 @@ With framework components:
5654
<script setup lang="ts">
5755
import { Comark } from '@comark/vue'
5856
import highlight from '@comark/vue/plugins/highlight'
59-
import githubLight from '@shikijs/themes/github-light'
60-
import githubDark from '@shikijs/themes/github-dark'
6157
6258
const plugins = [
6359
highlight({
64-
themes: { light: githubLight, dark: githubDark }
60+
themes: { light: 'github-light', dark: 'github-dark' }
6561
})
6662
]
6763
</script>
@@ -86,11 +82,9 @@ html.dark .shiki :deep(span) {
8682
```tsx [React]
8783
import { Comark } from '@comark/react'
8884
import highlight from '@comark/react/plugins/highlight'
89-
import githubLight from '@shikijs/themes/github-light'
90-
import githubDark from '@shikijs/themes/github-dark'
9185

9286
<Comark
93-
plugins={[highlight({ themes: { light: githubLight, dark: githubDark } })]}
87+
plugins={[highlight({ themes: { light: 'github-light', dark: 'github-dark' } })]}
9488
>
9589
{content}
9690
</Comark>
@@ -107,6 +101,20 @@ import githubDark from '@shikijs/themes/github-dark'
107101
Highlight code with different themes for light and dark modes. Both palettes are embedded as CSS custom properties, so there is no flash on theme switch. See all [available themes →](https://shiki.style/themes)
108102

109103
```typescript
104+
highlight({
105+
themes: {
106+
light: 'github-light',
107+
dark: 'github-dark'
108+
}
109+
})
110+
```
111+
112+
You can also pass theme registration objects (for example from `@shikijs/themes`) when you want explicit control over what gets bundled:
113+
114+
```typescript
115+
import githubLight from '@shikijs/themes/github-light'
116+
import githubDark from '@shikijs/themes/github-dark'
117+
110118
highlight({
111119
themes: {
112120
light: githubLight,
@@ -178,7 +186,7 @@ Pass any [Shiki transformer](https://shiki.style/guide/transformers) via `transf
178186
import { transformerNotationDiff } from '@shikijs/transformers'
179187

180188
highlight({
181-
themes: { light: githubLight, dark: githubDark },
189+
themes: { light: 'github-light', dark: 'github-dark' },
182190
transformers: [transformerNotationDiff()]
183191
})
184192
```
@@ -209,7 +217,7 @@ Returns a `ComarkPlugin` that enables Shiki syntax highlighting.
209217

210218
| Option | Type | Default | Description |
211219
|---|---|---|---|
212-
| [`themes`](#options-themes) | `object` | Material themes | Light and dark theme registrations |
220+
| [`themes`](#options-themes) | `object` | Material themes | Light and dark theme names or registrations |
213221
| [`languages`](#options-languages) | `LanguageRegistration[]` | `undefined` | Languages to preload |
214222
| [`transformers`](#options-transformers) | `ShikiTransformer[]` | `undefined` | Shiki transformers applied to every block |
215223
| [`preStyles`](#options-prestyles) | `boolean` | `false` | Add inline background/foreground styles to `<pre>` |
@@ -218,21 +226,18 @@ Returns a `ComarkPlugin` that enables Shiki syntax highlighting.
218226

219227
### `themes`
220228

221-
Theme configuration for light and dark modes. Import from `@shikijs/themes`.
229+
Theme configuration for light and dark modes. Each value can be a [bundled theme name](https://shiki.style/themes) string (resolved from `shiki`) or a theme registration object.
222230

223231
```typescript
224-
import githubLight from '@shikijs/themes/github-light'
225-
import githubDark from '@shikijs/themes/github-dark'
226-
227232
highlight({
228233
themes: {
229-
light: githubLight,
230-
dark: githubDark
234+
light: 'github-light',
235+
dark: 'github-dark'
231236
}
232237
})
233238
```
234239

235-
**Default:** `{ light: materialThemeLighter, dark: materialThemePalenight }`
240+
**Default:** `{ light: 'material-theme-lighter', dark: 'material-theme-palenight' }`
236241

237242
### `languages`
238243

@@ -296,7 +301,7 @@ When `true`, `material-theme-lighter` (light) and `material-theme-palenight` (da
296301
```typescript
297302
highlight({
298303
registerDefaultThemes: false,
299-
themes: { light: githubLight, dark: githubDark }
304+
themes: { light: 'github-light', dark: 'github-dark' }
300305
})
301306
```
302307

@@ -311,17 +316,15 @@ highlight({
311316
```typescript
312317
import { parse } from 'comark'
313318
import highlight from 'comark/plugins/highlight'
314-
import githubLight from '@shikijs/themes/github-light'
315-
import githubDark from '@shikijs/themes/github-dark'
316319

317320
const result = await parse(content, {
318-
plugins: [highlight({ themes: { light: githubLight, dark: githubDark } })]
321+
plugins: [highlight({ themes: { light: 'github-light', dark: 'github-dark' } })]
319322
})
320323
```
321324

322325
### Minimal Bundle
323326

324-
Disable defaults and import only what you need:
327+
Disable defaults and import only what you need. Prefer theme registration objects here so unused bundled themes are tree-shaken:
325328

326329
```typescript
327330
import javascript from '@shikijs/langs/javascript'
@@ -346,7 +349,7 @@ import {
346349
} from '@shikijs/transformers'
347350

348351
highlight({
349-
themes: { light: githubLight, dark: githubDark },
352+
themes: { light: 'github-light', dark: 'github-dark' },
350353
transformers: [
351354
transformerNotationDiff(), // [!code ++] / [!code --]
352355
transformerNotationHighlight(), // [!code highlight]

0 commit comments

Comments
 (0)