Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: shikijs/shiki
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.16.0
Choose a base ref
...
head repository: shikijs/shiki
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.16.1
Choose a head ref
  • 4 commits
  • 19 files changed
  • 1 contributor

Commits on Sep 1, 2024

  1. docs: typo

    antfu committed Sep 1, 2024
    Copy the full SHA
    cc80c37 View commit details
  2. pref: reuse EncodedTokenMetadata from @shikijs/vscode-textmate

    antfu committed Sep 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b0f3bb7 View commit details
  3. perf: externalize @shikijs/vscode-textmate

    antfu committed Sep 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a1e154d View commit details
  4. chore: release v1.16.1

    antfu committed Sep 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a71d08c View commit details
4 changes: 2 additions & 2 deletions docs/guide/sync-usage.md
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ const shiki = createHighlighterCoreSync({
const html = shiki.highlight('console.log(1)', { lang: 'js', theme: 'nord' })
```

When doing so, it requires all `themes` and `langs` to be provide as plain objects. Also an explicit `engine` is required to be provided. With the new [experimental JavaScript RegExp engine](http://localhost:5173/guide/regex-engines#javascript-regexp-engine-experimental) you are able to create an engine instance synchronously as well.
When doing so, it requires all `themes` and `langs` to be provide as plain objects. Also an explicit `engine` is required to be provided. With the new [experimental JavaScript RegExp engine](/guide/regex-engines#javascript-regexp-engine-experimental) you are able to create an engine instance synchronously as well.

The [Oniguruma Engine](http://localhost:5173/guide/regex-engines#oniguruma-engine) can only be created asynchronously, so you need to resolve the engine promise before creating the sync highlighter.
The [Oniguruma Engine](/guide/regex-engines#oniguruma-engine) can only be created asynchronously, so you need to resolve the engine promise before creating the sync highlighter.

```ts
import { createHighlighterCoreSync, createWasmOnigEngine } from 'shiki/core'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"private": true,
"packageManager": "pnpm@9.9.0",
"scripts": {
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/cli",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Shiki in the command line",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/compat/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/compat",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Shiki v0.x compatible API",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/core",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Core of Shiki",
"author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
10 changes: 7 additions & 3 deletions packages/core/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -32,6 +32,11 @@ const plugins = [
wasmPlugin(),
]

const external = [
'hast',
'@shikijs/vscode-textmate',
]

export default defineConfig([
{
input: entries,
@@ -46,6 +51,7 @@ export default defineConfig([
plugins: [
...plugins,
],
external,
},
{
input: entries,
@@ -70,9 +76,7 @@ export default defineConfig([
if (!/Circular|an empty chunk/.test(warning.message))
warn(warning)
},
external: [
'hast',
],
external,
},
])

7 changes: 3 additions & 4 deletions packages/core/src/highlight/code-to-tokens-base.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* ---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*-------------------------------------------------------- */
import { INITIAL } from '@shikijs/vscode-textmate'
import { EncodedTokenMetadata, INITIAL } from '@shikijs/vscode-textmate'
import type { IGrammar, IRawThemeSetting, StateStack } from '@shikijs/vscode-textmate'
import type { CodeToTokensBaseOptions, FontStyle, ShikiInternal, ThemeRegistrationResolved, ThemedToken, ThemedTokenScopeExplanation, TokenizeWithThemeOptions } from '../types'
import { applyColorReplacements, isNoneTheme, isPlainLang, resolveColorReplacements, splitLines } from '../utils'
import { ShikiError } from '../error'
import { GrammarState, getGrammarStack } from '../textmate/grammar-state'
import { StackElementMetadata } from '../textmate/stack-element-metadata'
import { tokenizeAnsiWithTheme } from './code-to-tokens-ansi'

/**
@@ -166,10 +165,10 @@ function _tokenizeWithTheme(

const metadata = result.tokens[2 * j + 1]
const color = applyColorReplacements(
colorMap[StackElementMetadata.getForeground(metadata)],
colorMap[EncodedTokenMetadata.getForeground(metadata)],
colorReplacements,
)
const fontStyle: FontStyle = StackElementMetadata.getFontStyle(metadata)
const fontStyle: FontStyle = EncodedTokenMetadata.getFontStyle(metadata)

const token: ThemedToken = {
content: line.substring(startIndex, nextStartIndex),
9 changes: 8 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ export { createWasmOnigEngine, loadWasm } from './engines/wasm'
export { createJavaScriptRegexEngine } from './engines/javascript'

// TextMate Utilities
export { StackElementMetadata } from './textmate/stack-element-metadata'
export { normalizeTheme } from './textmate/normalize-theme'

// Low-level Highlighting
@@ -27,3 +26,11 @@ export { codeToTokensWithThemes } from './highlight/code-to-tokens-themes'
export * from './utils'
export { transformerDecorations } from './transformer-decorations'
export { ShikiError } from './error'

// Deprecated
export {
/**
* @deprecated Use `EncodedTokenMetadata` from `@shikijs/vscode-textmate` instead.
*/
EncodedTokenMetadata as StackElementMetadata,
} from '@shikijs/vscode-textmate'
148 changes: 0 additions & 148 deletions packages/core/src/textmate/stack-element-metadata.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/markdown-it/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/markdown-it",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "markdown-it integration for shiki",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/monaco/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/monaco",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Use Shiki for Monaco Editor",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
5 changes: 2 additions & 3 deletions packages/monaco/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type monacoNs from 'monaco-editor-core'
import type { ShikiInternal, ThemeRegistrationResolved } from '@shikijs/core'
import type { StateStack } from '@shikijs/vscode-textmate'
import { INITIAL } from '@shikijs/vscode-textmate'
import { StackElementMetadata } from '@shikijs/core'
import { EncodedTokenMetadata, INITIAL } from '@shikijs/vscode-textmate'

export interface MonacoTheme extends monacoNs.editor.IStandaloneThemeData {}

@@ -132,7 +131,7 @@ export function shikiToMonaco(
for (let j = 0; j < tokensLength; j++) {
const startIndex = result.tokens[2 * j]
const metadata = result.tokens[2 * j + 1]
const color = normalizeColor(colorMap[StackElementMetadata.getForeground(metadata)] || '')
const color = normalizeColor(colorMap[EncodedTokenMetadata.getForeground(metadata)] || '')
// Because Monaco only support one scope per token,
// we workaround this to use color to trace back the scope
const scope = findScopeByColor(color) || ''
2 changes: 1 addition & 1 deletion packages/rehype/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/rehype",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "rehype integration for shiki",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/shiki/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shiki",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "A beautiful Syntax Highlighter.",
"author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/transformers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/transformers",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Collective of common transformers transformers for Shiki",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/twoslash/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/twoslash",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Shiki transformer for twoslash",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/vitepress-twoslash/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shikijs/vitepress-twoslash",
"type": "module",
"version": "1.16.0",
"version": "1.16.1",
"description": "Enable Twoslash support in VitePress",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
Loading