Skip to content

Commit 87f943a

Browse files
nadeshiko@eecs.berkeley.eduaxmmisaka
authored andcommitted
Migrate syntax highlighter from Shikiji to Shiki, and made relevant changes
See shikijs/shiki#557, shikiji backported to shiki; this commit changed all reference to "shikiji" to be "shiki"; actual code logic are not affected.
1 parent f1a702a commit 87f943a

File tree

8 files changed

+30
-43
lines changed

8 files changed

+30
-43
lines changed

docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const config: Config = {
174174

175175

176176
clientModules: [
177-
"src/components/ShikijiLFHighlighter/shikijiloader.ts"
177+
"src/components/ShikiLFHighlighter/shikiloader.ts"
178178
],
179179
};
180180

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"react": "^18.0.0",
2727
"react-dom": "^18.0.0",
2828
"react-transition-group": "^4.4.5",
29-
"shikiji": "^0.7.4",
29+
"shiki": "^1.5.1",
3030
"unist-util-visit": "^5.0.0"
3131
},
3232
"devDependencies": {

src/components/LinguaFrancaMultiTargetUtils/LangSpecific.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import TabItem from "@theme/TabItem";
44
import styles from "./styles.module.css";
55
import CodeBlock from "@theme/CodeBlock";
66
import { ReactNode, useEffect, useState } from "react";
7-
import { ShikijiLFHighlighter } from "../ShikijiLFHighlighter";
7+
import { ShikiLFHighlighter } from "../ShikiLFHighlighter";
88

99
interface WebpackImportedRawModule {
1010
default: Readonly<Record<string, string>>;
@@ -47,7 +47,7 @@ export const NoSelectorTargetCodeBlock = (
4747
string | Promise<WebpackImportedRawModule | null>
4848
>),
4949
): JSX.Element => {
50-
const Component = props.lf ? ShikijiLFHighlighter : CodeBlock;
50+
const Component = props.lf ? ShikiLFHighlighter : CodeBlock;
5151
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5252
const { lf, ...targetToCode } = props;
5353
const newProps: Record<TargetsType, ReactNode> = {} as Record<

src/components/ShikijiLFHighlighter/index.tsx renamed to src/components/ShikiLFHighlighter/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from "react";
2-
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shikiji";
3-
import { loadShikiji } from "./shikijiloader";
2+
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shiki";
3+
import { loadShiki } from "./shikiloader";
44
import { useColorMode } from "@docusaurus/theme-common";
55
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
66

@@ -12,7 +12,7 @@ declare global {
1212
}
1313
}
1414

15-
export const ShikijiLFHighlighter = ({
15+
export const ShikiLFHighlighter = ({
1616
children,
1717
...props
1818
}: { children: string } & Record<string, unknown>) => {
@@ -28,7 +28,7 @@ export const ShikijiLFHighlighter = ({
2828
useEffect(() => {
2929
(async () => {
3030
if (!isBrowser) return;
31-
const shiki = await loadShikiji();
31+
const shiki = await loadShiki();
3232
setCode(
3333
shiki.codeToHtml(children, {
3434
lang: "Lingua Franca",
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
2-
import { LanguageRegistration, getHighlighter } from "shikiji";
2+
import { LanguageRegistration, getHighlighter } from "shiki";
33
import { targets } from "@site/src/components/LinguaFrancaMultiTargetUtils";
44
import LFTextMateLanguageDefinition from "./lflang.tmLanguage.json";
5-
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shikiji";
5+
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shiki";
66

77
declare global {
88
interface Window {
@@ -12,11 +12,11 @@ declare global {
1212
}
1313
}
1414

15-
export const loadShikiji = async () => {
15+
export const loadShiki = async () => {
1616
if (window.LFWebsite?.shikijiInstance != null) {
1717
return window.LFWebsite.shikijiInstance;
1818
}
19-
const shikiji = await getHighlighter({
19+
const shiki = await getHighlighter({
2020
themes: ["material-theme-lighter", "material-theme-darker"],
2121
langs: [
2222
...targets,
@@ -27,19 +27,19 @@ export const loadShikiji = async () => {
2727
if (window.LFWebsite == null) {
2828
window.LFWebsite = {};
2929
}
30-
window.LFWebsite.shikijiInstance = shikiji;
31-
return shikiji;
30+
window.LFWebsite.shikijiInstance = shiki;
31+
return shiki;
3232
};
3333

3434
if (ExecutionEnvironment.canUseDOM) {
3535
// As soon as the site loads in the browser, check if a Shikiji instance is created. If not, create one and save to global.
3636

3737
// Don't catch. Let it throw~ let it throw~
38-
loadShikiji().then((v) => {
38+
loadShiki().then((v) => {
3939
if (v != null) {
40-
console.log("Shikiji is loaded.");
40+
console.log("Shiki loaded.");
4141
} else {
42-
throw Error("Shikiji not loaded correctly.");
42+
throw Error("Shiki did loaded correctly.");
4343
}
4444
});
4545
}

src/theme/CodeBlock/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from "react";
22
import CodeBlock from "@theme-original/CodeBlock";
3-
import { ShikijiLFHighlighter } from "@site/src/components/ShikijiLFHighlighter";
3+
import { ShikiLFHighlighter } from "@site/src/components/ShikiLFHighlighter";
44

55
export default function CodeBlockWrapper(props) {
66
return (
77
<>
88
{/* If using <CodeBlock /> then it will contain language="lf-c"; if using ``` it will contain className="language-lf-c". */}
99
{props.language?.startsWith("lf") ||
1010
props.className?.startsWith("language-lf") ? (
11-
<ShikijiLFHighlighter {...props} />
11+
<ShikiLFHighlighter {...props} />
1212
) : (
1313
<CodeBlock {...props} />
1414
)}

yarn.lock

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,11 @@
19081908
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.23.tgz#498e41218ab3b6a1419c735e5c6ae2c5ed609b6c"
19091909
integrity sha512-C16M+IYz0rgRhWZdCmK+h58JMv8vijAA61gmz2rspCSwKwzBebpdcsiUmwrtJRdphuY30i6BSLEOP8ppbNLyLg==
19101910

1911+
"@shikijs/[email protected]":
1912+
version "1.5.1"
1913+
resolved "https://registry.yarnpkg.com/@shikijs/core/-/core-1.5.1.tgz#22d8c3a43c66c30eea3988615ec6a947a1957ea3"
1914+
integrity sha512-xjV63pRUBvxA1LsxOUhRKLPh0uUjwBLzAKLdEuYSLIylo71sYuwDcttqNP01Ib1TZlLfO840CXHPlgUUsYFjzg==
1915+
19111916
"@sideway/address@^4.1.3":
19121917
version "4.1.4"
19131918
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0"
@@ -4929,24 +4934,6 @@ hast-util-to-estree@^3.0.0:
49294934
unist-util-position "^5.0.0"
49304935
zwitch "^2.0.0"
49314936

4932-
hast-util-to-html@^9.0.0:
4933-
version "9.0.0"
4934-
resolved "https://registry.yarnpkg.com/hast-util-to-html/-/hast-util-to-html-9.0.0.tgz#51c0ae2a3550b9aa988c094c4fc4e327af0dddd1"
4935-
integrity sha512-IVGhNgg7vANuUA2XKrT6sOIIPgaYZnmLx3l/CCOAK0PtgfoHrZwX7jCSYyFxHTrGmC6S9q8aQQekjp4JPZF+cw==
4936-
dependencies:
4937-
"@types/hast" "^3.0.0"
4938-
"@types/unist" "^3.0.0"
4939-
ccount "^2.0.0"
4940-
comma-separated-tokens "^2.0.0"
4941-
hast-util-raw "^9.0.0"
4942-
hast-util-whitespace "^3.0.0"
4943-
html-void-elements "^3.0.0"
4944-
mdast-util-to-hast "^13.0.0"
4945-
property-information "^6.0.0"
4946-
space-separated-tokens "^2.0.0"
4947-
stringify-entities "^4.0.0"
4948-
zwitch "^2.0.4"
4949-
49504937
hast-util-to-jsx-runtime@^2.0.0:
49514938
version "2.3.0"
49524939
resolved "https://registry.yarnpkg.com/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.0.tgz#3ed27caf8dc175080117706bf7269404a0aa4f7c"
@@ -8171,12 +8158,12 @@ shelljs@^0.8.5:
81718158
interpret "^1.0.0"
81728159
rechoir "^0.6.2"
81738160

8174-
shikiji@^0.7.4:
8175-
version "0.7.5"
8176-
resolved "https://registry.yarnpkg.com/shikiji/-/shikiji-0.7.5.tgz#43a634853f0e32c1b9939a9d4f587c570f009561"
8177-
integrity sha512-He8lAcTZUVuUW+Z4VRPM+TP+HVZCe4R1qzrP7voUrmAKrFKE260YEUVgqcP7y/0ps0uVvKgVhu5vgIshGpGocQ==
8161+
shiki@^1.5.1:
8162+
version "1.5.1"
8163+
resolved "https://registry.yarnpkg.com/shiki/-/shiki-1.5.1.tgz#573602bb0f2d54f233b6a0102de7be8274ca5cab"
8164+
integrity sha512-vx4Ds3M3B9ZEmLeSXqBAB85osBWV8ErZfP69kuFQZozPgHc33m7spLTCUkcjwEjFm3gk3F9IdXMv8kX+v9xDHA==
81788165
dependencies:
8179-
hast-util-to-html "^9.0.0"
8166+
"@shikijs/core" "1.5.1"
81808167

81818168
side-channel@^1.0.4:
81828169
version "1.0.4"
@@ -9170,7 +9157,7 @@ yocto-queue@^1.0.0:
91709157
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251"
91719158
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==
91729159

9173-
zwitch@^2.0.0, zwitch@^2.0.4:
9160+
zwitch@^2.0.0:
91749161
version "2.0.4"
91759162
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-2.0.4.tgz#c827d4b0acb76fc3e685a4c6ec2902d51070e9d7"
91769163
integrity sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==

0 commit comments

Comments
 (0)