Skip to content

Commit 4b0b1ef

Browse files
authoredOct 30, 2022
fix(build): use addClass from shiki-processor (#1557)
reverts #1546 (fixed in upstream) fixes #1555
1 parent 8cd1f7c commit 4b0b1ef

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"@vueuse/core": "^9.4.0",
8989
"body-scroll-lock": "4.0.0-beta.0",
9090
"shiki": "^0.11.1",
91-
"shiki-processor": "^0.1.0",
9291
"vite": "^3.1.8",
9392
"vue": "^3.2.41"
9493
},
@@ -157,6 +156,7 @@
157156
"semver": "^7.3.8",
158157
"simple-git-hooks": "^2.8.1",
159158
"sirv": "^2.0.2",
159+
"shiki-processor": "^0.1.1",
160160
"supports-color": "^9.2.3",
161161
"typescript": "~4.8.4",
162162
"vitest": "^0.24.3",

‎pnpm-lock.yaml

+5-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/node/markdown/plugins/highlight.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { IThemeRegistration, HtmlRendererOptions } from 'shiki'
1+
import type { HtmlRendererOptions, IThemeRegistration } from 'shiki'
22
import {
3+
addClass,
34
createDiffProcessor,
45
createFocusProcessor,
56
createHighlightProcessor,
67
createRangeProcessor,
8+
defineProcessor,
79
getHighlighter,
8-
Processor,
9-
defineProcessor
10+
type Processor
1011
} from 'shiki-processor'
1112
import type { ThemeOptions } from '../markdown'
1213

@@ -68,7 +69,6 @@ export async function highlight(
6869
processors
6970
})
7071

71-
const classRE = /<pre[^>]*class="(.*?)"/
7272
const styleRE = /<pre[^>]*(style=".*?")/
7373
const preRE = /^<pre(.*?)>/
7474
const vueRE = /-vue$/
@@ -93,21 +93,29 @@ export async function highlight(
9393
)
9494
}
9595

96-
const dark = cleanup(
97-
highlighter.codeToHtml(str, {
98-
lang,
99-
lineOptions,
100-
theme: getThemeName(theme.dark)
101-
})
102-
).replace(classRE, (_, cls) => _.replace(cls, 'vp-code-dark'))
96+
const dark = addClass(
97+
cleanup(
98+
highlighter.codeToHtml(str, {
99+
lang,
100+
lineOptions,
101+
theme: getThemeName(theme.dark)
102+
})
103+
),
104+
'vp-code-dark',
105+
'pre'
106+
)
103107

104-
const light = cleanup(
105-
highlighter.codeToHtml(str, {
106-
lang,
107-
lineOptions,
108-
theme: getThemeName(theme.light)
109-
})
110-
).replace(classRE, (_, cls) => _.replace(cls, 'vp-code-light'))
108+
const light = addClass(
109+
cleanup(
110+
highlighter.codeToHtml(str, {
111+
lang,
112+
lineOptions,
113+
theme: getThemeName(theme.light)
114+
})
115+
),
116+
'vp-code-light',
117+
'pre'
118+
)
111119

112120
return dark + light
113121
}

0 commit comments

Comments
 (0)
Please sign in to comment.