-
-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,766 additions
and
1,399 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
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
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
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,33 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Bundles | ||
|
||
The main `shikiji` entries bundles all supported themes and languages via lazy dynamic imports. The efficiency shouldn't be a concern to most of the scenarios as the grammar would only be imported/downloaded when it is used. However, when you bundle Shikiji into browsers runtime or web workers, even those files are not imported, they still add up to your dist size. We provide the [fine-grained bundle](/guide/install#fine-grained-bundle) to help you compose languages and themes one-by-one as you need. | ||
|
||
To make it easier, we also provide some pre-composed bundles for you to use: | ||
|
||
## `shikiji/bundle/full` | ||
|
||
The full bundle includes all themes and languages, same as the main `shikiji` entry. | ||
|
||
## `shikiji/bundle/web` | ||
|
||
The bundle the includes all themes and common web languages like (HTML, CSS, JS, TS, JSON, Markdown, etc.) and some web frameworks (Vue, JSX, Svelte, etc.). | ||
|
||
Use as normal, all functions from `shikiji` are also available in the bundle: | ||
|
||
```ts | ||
import { | ||
BundledLanguage, | ||
BundledTheme, | ||
codeToHtml, | ||
getHighlighter | ||
} from 'shikiji/bundle/web' // [!code highlight] | ||
const highlighter = await getHighlighter({ | ||
langs: ['html', 'css', 'js'], | ||
themes: ['github-dark', 'github-light'], | ||
}) | ||
``` |
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 |
---|---|---|
|
@@ -126,6 +126,10 @@ const code = shiki.codeToHtml('const a = 1', { | |
}) | ||
``` | ||
|
||
### Bundle Presets | ||
|
||
We also provide some pre-composed bundles for you to use easily, learn more about them in the [bundles section](/guide/bundles). | ||
|
||
### CJS Usage | ||
|
||
`shikiji` is published as ESM-only to reduce the package size. It's still possible to use it in CJS, as Node.js supports importing ESM modules dynamically in CJS. | ||
|
@@ -138,7 +142,7 @@ import { getHighlighter } from 'shikiji' | |
|
||
async function main() { | ||
const shiki = await getHighlighter({ | ||
themes: ['nord'], | ||
themes: ['vitesse-dark'], | ||
langs: ['javascript'], | ||
}) | ||
|
||
|
@@ -154,7 +158,7 @@ async function main() { | |
const { getHighlighter } = await import('shikiji') | ||
|
||
const shiki = await getHighlighter({ | ||
themes: ['nord'], | ||
themes: ['vitesse-dark'], | ||
langs: ['javascript'], | ||
}) | ||
|
||
|
@@ -166,7 +170,7 @@ async function main() { | |
|
||
To use `shikiji` in the browser via CDN, you can use [esm.run](https://esm.run) or [esm.sh](https://esm.sh). | ||
|
||
```html | ||
```html theme:rose-pine | ||
<body> | ||
<div id="foo"></div> | ||
|
||
|
@@ -177,7 +181,10 @@ To use `shikiji` in the browser via CDN, you can use [esm.run](https://esm.run) | |
// import { codeToHtml } from 'https://esm.run/[email protected]' | ||
const foo = document.getElementById('foo') | ||
foo.innerHTML = await codeToHtml('console.log("Hi, Shiki on CDN :)")', { lang: 'js', theme: 'vitesse-light' }) | ||
foo.innerHTML = await codeToHtml('console.log("Hi, Shiki on CDN :)")', { | ||
lang: 'js', | ||
theme: 'rose-pine' | ||
}) | ||
</script> | ||
</body> | ||
``` | ||
|
@@ -192,7 +199,7 @@ Cloudflare Workers [does not support initializing WebAssembly from binary data]( | |
|
||
Meanwhile, it's also recommended to use the [Fine-grained Bundle](#fine-grained-bundle) approach to reduce the bundle size. | ||
|
||
```ts | ||
```ts theme:nord | ||
import { getHighlighterCore, loadWasm } from 'shikiji/core' | ||
import nord from 'shikiji/themes/nord.mjs' | ||
import js from 'shikiji/langs/javascript.mjs' | ||
|
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
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 |
---|---|---|
|
@@ -24,8 +24,8 @@ | |
"@rollup/plugin-terser": "^0.4.4", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/hast": "^3.0.3", | ||
"@types/node": "^20.10.4", | ||
"@vitest/coverage-v8": "^1.0.4", | ||
"@types/node": "^20.10.5", | ||
"@vitest/coverage-v8": "^1.1.0", | ||
"ansi-sequence-parser": "^1.1.1", | ||
"bumpp": "^9.2.1", | ||
"eslint": "npm:[email protected]", | ||
|
@@ -42,7 +42,7 @@ | |
"pnpm": "^8.12.1", | ||
"prettier": "^3.1.1", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.9.0", | ||
"rollup": "^4.9.1", | ||
"rollup-plugin-copy": "^3.5.0", | ||
"rollup-plugin-dts": "^6.1.0", | ||
"rollup-plugin-esbuild": "^6.1.0", | ||
|
@@ -53,9 +53,9 @@ | |
"typescript": "^5.3.3", | ||
"unbuild": "^2.0.0", | ||
"vite": "^5.0.10", | ||
"vitest": "^1.0.4", | ||
"vitest": "^1.1.0", | ||
"vue-tsc": "^1.8.25", | ||
"wrangler": "^3.21.0" | ||
"wrangler": "^3.22.1" | ||
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
|
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
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
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
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
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.