Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "shikiji", | ||
"type": "module", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"packageManager": "pnpm@8.6.12", | ||
@@ -6,0 +6,0 @@ "description": "An ESM-focused rewrite of shiki", |
@@ -45,21 +45,29 @@ # Shikiji 式辞 | ||
#### Shorthands | ||
Unlike `shiki`, `shikiji` does not load any themes or languages when not specified. | ||
In addition to the `getHighlighter` function, `shikiji` also provides some shorthand functions for simplier usage. | ||
```js | ||
import { codeToHtml } from 'shikiji' | ||
import { getHighlighter } from 'shikiji' | ||
const code1 = await codeToHtml('const a = 1', { lang: 'javascript', theme: 'nord' }) | ||
const code2 = await codeToHtml('<div class="foo">bar</div>', { lang: 'html', theme: 'min-dark' }) | ||
const shiki = await getHighlighter() | ||
shiki.codeToHtml('const a = 1', { lang: 'javascript' }) // throws error, `javascript` is not loaded | ||
await shiki.loadLanguage('javascript') // load the language | ||
``` | ||
Currently supports: | ||
If you want to load all themes and languages (not recommended), you can iterate all keys from `bundledLanguages` and `bundledThemes`. | ||
- `codeToThemedTokens` | ||
- `codeToHtml` | ||
- `codeToHtmlDualThemes` | ||
```js | ||
import { bundledLanguages, bundledThemes, getHighlighter } from 'shikiji' | ||
Internally they maintains 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. | ||
const shiki = await getHighlighter({ | ||
themes: Object.keys(bundledThemes), | ||
langs: Object.keys(bundledLanguages), | ||
}) | ||
shiki.codeToHtml('const a = 1', { lang: 'javascript' }) | ||
``` | ||
Or if your usage can be async, you can try the [shorthands](#shorthands) which will load the theme/language on demand. | ||
### Fine-grained Bundle | ||
@@ -169,2 +177,23 @@ | ||
### Shorthands | ||
In addition to the `getHighlighter` function, `shikiji` also provides some shorthand functions for simpler usage. | ||
```js | ||
import { codeToHtml, codeToThemedTokens } from 'shikiji' | ||
const code = await codeToHtml('const a = 1', { lang: 'javascript', theme: 'nord' }) | ||
const tokens = await codeToThemedTokens('<div class="foo">bar</div>', { lang: 'html', theme: 'min-dark' }) | ||
``` | ||
Currently supports: | ||
- `codeToThemedTokens` | ||
- `codeToHtml` | ||
- `codeToHtmlDualThemes` | ||
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. | ||
> **Note:** These are only available in the [bundled usage](#bundled-usage), a.k.a the main `shikiji` entry. If you are using the [fine-grained bundle](#fine-grained-bundle), you can create your own shorthands by porting [this file](https://github.com/antfu/shikiji/blob/main/src/bundled/shorthands.ts). | ||
### Light/Dark Dual Themes | ||
@@ -171,0 +200,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7064955
26964
290