You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constcode=shiki.codeToHtml('const a = 1', { lang:'javascript' })
106
+
constcode=shiki.codeToHtml('const a = 1', { lang:'javascript', theme:'nord' })
107
107
```
108
108
109
109
### CJS Usage
@@ -197,6 +197,15 @@ export default {
197
197
198
198
## Additional Features
199
199
200
+
### `codeToHast`
201
+
202
+
`shikiji` used [`hast`](https://github.com/syntax-tree/hast) to generate HTML. You can use `codeToHast` to generate the AST and use it with tools like [unified](https://github.com/unifiedjs).
203
+
204
+
```js
205
+
constroot=shiki.codeToHast('const a = 1', { lang:'javascript', theme:'nord' })
206
+
```
207
+
208
+
200
209
### Shorthands
201
210
202
211
In addition to the `getHighlighter` function, `shikiji` also provides some shorthand functions for simpler usage.
@@ -212,7 +221,7 @@ Currently supports:
212
221
213
222
-`codeToThemedTokens`
214
223
-`codeToHtml`
215
-
-`codeToHtmlThemes`
224
+
-`codeToHast`
216
225
217
226
Internally they maintain a singleton highlighter instance and load the theme/language on demand. Different from `shiki.codeToHtml`, the `codeToHtml` shorthand function returns a Promise and `lang` and `theme` options are required.
218
227
@@ -222,7 +231,7 @@ Internally they maintain a singleton highlighter instance and load the theme/lan
222
231
223
232
`shikiji` added an experimental light/dark dual themes support. Different from [markdown-it-shiki](https://github.com/antfu/markdown-it-shiki#dark-mode)'s approach which renders the code twice, `shikiji`'s dual themes approach uses CSS variables to store the colors on each token. It's more performant with a smaller bundle size.
224
233
225
-
Use `codeToHtmlThemes`to render the code with dual themes:
234
+
Changing the `theme` option in `codeToHtml`to `options` with `light` and `dark` key to generate with two themes.
It's also possible to support more than two themes. In the `themes` object, you can have an arbitrary number of themes, and specify the default theme with `defaultColor` option.
@@ -323,7 +332,7 @@ And then update your CSS snippet to control then each theme taking effect. Here
323
332
If you want to take full control of the colors, or avoid using `!important` to override, you can optionally disable the default color by setting `defaultColor` to `false`.
@@ -343,6 +352,17 @@ In that case, the generated HTML would have no style out of the box, you need to
343
352
344
353
It's also possible to control the theme in CSS variables, for more, reference to the great research and examples by [@mayank99](https://github.com/mayank99) in [this issue #6](https://github.com/antfu/shikiji/issues/6).
345
354
355
+
## Breaking Changes from Shiki
356
+
357
+
As of [`shiki@0.4.3`](https://github.com/shikijs/shiki/releases/tag/v0.14.3):
358
+
359
+
- Top level named export `setCDN`, `loadLanguage`, `loadLanguage`, `setWasm`, are dropped.
360
+
-`BUNDLED_LANGUAGES`, `BUNDLED_THEMES` are moved to `shikiji/langs` and `shikiji/themes` and renamed to `bundledLanguages` and `bundledThemes` respectively.
361
+
-`theme` option for `getHighlighter` is dropped, use `themes` with an array instead.
362
+
- Highlighter does not maintain an internal default theme context. `theme` option is required for `codeToHtml` and `codeToThemedTokens`.
363
+
- CJS and IIFE builds are dropped.
364
+
-`LanguageRegistration`'s `grammar` field if flattened to `LanguageRegistration` itself (refer to the types for more details).
365
+
346
366
## Bundle Size
347
367
348
368
You can inspect the bundle size in detail on [pkg-size.dev/shikiji](https://pkg-size.dev/shikiji).
Copy file name to clipboardexpand all lines: packages/shikiji/README.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -209,7 +209,7 @@ Currently supports:
209
209
210
210
-`codeToThemedTokens`
211
211
-`codeToHtml`
212
-
-`codeToHtmlThemes`
212
+
-`codeToHast`
213
213
214
214
Internally they maintain a singleton highlighter instance and load the theme/language on demand. Different from `shiki.codeToHtml`, the `codeToHtml` shorthand function returns a Promise and `lang` and `theme` options are required.
215
215
@@ -219,7 +219,7 @@ Internally they maintain a singleton highlighter instance and load the theme/lan
219
219
220
220
`shikiji` added an experimental light/dark dual themes support. Different from [markdown-it-shiki](https://github.com/antfu/markdown-it-shiki#dark-mode)'s approach which renders the code twice, `shikiji`'s dual themes approach uses CSS variables to store the colors on each token. It's more performant with a smaller bundle size.
221
221
222
-
Use `codeToHtmlThemes` to render the code with dual themes:
222
+
Use `codeToHtml` to render the code with dual themes:
It's also possible to support more than two themes. In the `themes` object, you can have an arbitrary number of themes, and specify the default theme with `defaultColor` option.
@@ -320,7 +320,7 @@ And then update your CSS snippet to control then each theme taking effect. Here
320
320
If you want to take full control of the colors, or avoid using `!important` to override, you can optionally disable the default color by setting `defaultColor` to `false`.
0 commit comments