Skip to content

Commit a62d822

Browse files
committed
refactor: use web bundle
1 parent f7d3690 commit a62d822

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/components/Markdown.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { FaRegCopy } from 'react-icons/fa'
33
import { MarkdownLink } from '~/components/MarkdownLink'
44
import type { HTMLProps } from 'react'
5-
import { createHighlighter as shikiGetHighlighter } from 'shiki/bundle-full.mjs'
5+
import { createHighlighter as shikiGetHighlighter } from 'shiki/bundle-web.mjs'
66
import { transformerNotationDiff } from '@shikijs/transformers'
77
import parse, {
88
attributesToProps,
@@ -134,10 +134,10 @@ export function CodeBlock({
134134
const [codeElement, setCodeElement] = React.useState(
135135
<>
136136
<pre ref={ref} className={`shiki github-light h-full`}>
137-
<code>{code}</code>
137+
<code>{lang === 'mermaid' ? <svg /> : code}</code>
138138
</pre>
139139
<pre className={`shiki tokyo-night`}>
140-
<code>{code}</code>
140+
<code>{lang === 'mermaid' ? <svg /> : code}</code>
141141
</pre>
142142
</>
143143
)
@@ -153,7 +153,7 @@ export function CodeBlock({
153153
const htmls = await Promise.all(
154154
themes.map(async (theme) => {
155155
const output = highlighter.codeToHtml(code, {
156-
lang,
156+
lang: lang === 'mermaid' ? 'plaintext' : lang,
157157
theme,
158158
transformers: [transformerNotationDiff()],
159159
})
@@ -256,7 +256,11 @@ const getHighlighter = cache(async (language: string, themes: string[]) => {
256256

257257
let promises = []
258258
if (!loadedLanguages.includes(language as any)) {
259-
promises.push(highlighter.loadLanguage(language as any))
259+
promises.push(
260+
highlighter.loadLanguage(
261+
language === 'mermaid' ? 'plaintext' : (language as any)
262+
)
263+
)
260264
}
261265

262266
for (const theme of themes) {

0 commit comments

Comments
 (0)