@vuepress/plugin-shiki 2.0.0-rc.123 → 2.0.0-rc.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,276 @@
1
+ import { MarkdownItCodeBlockTitleOptions, MarkdownItCollapsedLinesOptions, MarkdownItLineNumbersOptions, WhitespacePosition } from "@vuepress/highlighter-helper";
2
+ import { BundledLanguage, BundledTheme, Highlighter, LanguageInput, ShikiTransformer, SpecialLanguage, StringLiteralUnion, ThemeRegistrationAny } from "shiki";
3
+ import { ShikiTwoslashOptions } from "@vuepress/shiki-twoslash";
4
+ import { Plugin } from "vuepress/core";
5
+
6
+ //#region src/node/types.d.ts
7
+ /**
8
+ * Shiki language type
9
+ *
10
+ * Shiki 语言类型
11
+ */
12
+ type ShikiLang = LanguageInput | SpecialLanguage | StringLiteralUnion<BundledLanguage>;
13
+ /**
14
+ * Shiki theme type
15
+ *
16
+ * Shiki 主题类型
17
+ */
18
+ type ShikiTheme = StringLiteralUnion<BundledTheme> | ThemeRegistrationAny;
19
+ /**
20
+ * Single theme options for Shiki
21
+ *
22
+ * Shiki 单主题配置
23
+ */
24
+ interface ShikiSingleThemeOptions {
25
+ /**
26
+ * The single theme to use
27
+ *
28
+ * @see https://shiki.style/themes
29
+ *
30
+ * @default 'nord'
31
+ */
32
+ theme?: ShikiTheme;
33
+ }
34
+ /**
35
+ * Dual theme options for Shiki
36
+ *
37
+ * Shiki 双主题配置
38
+ */
39
+ interface ShikiDualThemeOptions {
40
+ /**
41
+ * The dark and light themes to use
42
+ *
43
+ * @see https://shiki.style/themes
44
+ */
45
+ themes: {
46
+ dark: ShikiTheme;
47
+ light: ShikiTheme;
48
+ };
49
+ }
50
+ /**
51
+ * Shiki theme options
52
+ *
53
+ * Shiki 主题配置选项
54
+ */
55
+ type ShikiThemeOptions = ShikiDualThemeOptions | ShikiSingleThemeOptions;
56
+ /**
57
+ * Shiki highlight options
58
+ *
59
+ * Shiki 高亮配置选项
60
+ */
61
+ type ShikiHighlightOptions = ShikiThemeOptions & {
62
+ /**
63
+ * Languages to be loaded.
64
+ *
65
+ * Shiki does not preload any languages to avoid extra overhead. So you need
66
+ * to specify the languages you want to use.
67
+ *
68
+ * 要加载的语言。
69
+ *
70
+ * Shiki 不会预加载任何语言以避免额外开销。所以你需要指定要使用的语言。
71
+ *
72
+ * @see https://shiki.style/languages
73
+ */
74
+ langs?: ShikiLang[];
75
+ /**
76
+ * Language alias
77
+ *
78
+ * 语言别名
79
+ *
80
+ * @see https://shiki.style/guide/load-lang#custom-language-aliases
81
+ */
82
+ langAlias?: Record<string, StringLiteralUnion<BundledLanguage>>;
83
+ /**
84
+ * Fallback language when the specified language is not available.
85
+ *
86
+ * 指定语言不可用时的备选语言。
87
+ *
88
+ * @default 'plain'
89
+ */
90
+ defaultLang?: string;
91
+ /**
92
+ * Function to customize Shiki highlighter instance.
93
+ *
94
+ * 自定义 Shiki 高亮器实例的函数。
95
+ */
96
+ shikiSetup?: (shiki: Highlighter) => Promise<void> | void;
97
+ /**
98
+ * Shiki transformers
99
+ *
100
+ * Shiki 转换器
101
+ */
102
+ transformers?: ShikiTransformer[];
103
+ /**
104
+ * Enable highlight lines or not
105
+ *
106
+ * 是否启用行高亮
107
+ *
108
+ * @default true
109
+ */
110
+ highlightLines?: boolean;
111
+ /**
112
+ * Enable notation diff transformer
113
+ *
114
+ * 是否启用差异标记转换器
115
+ *
116
+ * @default false
117
+ *
118
+ * @see https://shiki.style/packages/transformers#transformernotationdiff
119
+ */
120
+ notationDiff?: boolean;
121
+ /**
122
+ * Enable notation focus transformer
123
+ *
124
+ * 是否启用聚焦标记转换器
125
+ *
126
+ * @default false
127
+ *
128
+ * @see https://shiki.style/packages/transformers#transformernotationfocus
129
+ */
130
+ notationFocus?: boolean;
131
+ /**
132
+ * Enable notation highlight transformer
133
+ *
134
+ * 是否启用高亮标记转换器
135
+ *
136
+ * @default false
137
+ *
138
+ * @see https://shiki.style/packages/transformers#transformernotationhighlight
139
+ */
140
+ notationHighlight?: boolean;
141
+ /**
142
+ * Enable notation error level transformer
143
+ *
144
+ * 是否启用错误级别标记转换器
145
+ *
146
+ * @default false
147
+ *
148
+ * @see https://shiki.style/packages/transformers#transformernotationerrorlevel
149
+ */
150
+ notationErrorLevel?: boolean;
151
+ /**
152
+ * Enable notation word highlight transformer
153
+ *
154
+ * 是否启用单词高亮标记转换器
155
+ *
156
+ * @default false
157
+ *
158
+ * @see https://shiki.style/packages/transformers#transformernotationwordhighlight
159
+ */
160
+ notationWordHighlight?: boolean;
161
+ /**
162
+ * Enable remove comments transformer
163
+ *
164
+ * 是否启用移除注释转换器
165
+ *
166
+ * @default false
167
+ *
168
+ * @see https://shiki.style/packages/transformers#transformerremovecomments
169
+ */
170
+ removeComments?: boolean;
171
+ /**
172
+ * Enable whitespace
173
+ * - true: enable whitespace, but not render any whitespace by default
174
+ * - false: disable whitespace completely
175
+ * - 'all': render all whitespace
176
+ * - 'boundary': render leading and trailing whitespace of each line.
177
+ * - 'leading': render leading whitespace of each line
178
+ * - 'trailing': render trailing whitespace of each line
179
+ *
180
+ * you are able to use `:whitespace` or `:no-whitespace` or `:whitespace=all|boundary|leading|trailing` to set single code block
181
+ *
182
+ * 启用空白字符显示
183
+ * - true: 启用空白字符,但默认不渲染任何空白字符
184
+ * - false: 完全禁用空白字符
185
+ * - 'all': 渲染所有空白字符
186
+ * - 'boundary': 渲染每行的前导和尾随空白字符
187
+ * - 'leading': 渲染每行的前导空白字符
188
+ * - 'trailing': 渲染每行的尾随空白字符
189
+ *
190
+ * 你可以使用 `:whitespace` 或 `:no-whitespace` 或 `:whitespace=all|boundary|leading|trailing` 来设置单个代码块
191
+ *
192
+ * @default false
193
+ *
194
+ * @see https://shiki.style/packages/transformers#transformerrenderwhitespace
195
+ */
196
+ whitespace?: WhitespacePosition | boolean;
197
+ /**
198
+ * Log level Highlighter language detecter
199
+ *
200
+ * 高亮器语言检测器的日志级别
201
+ *
202
+ * @description defaults to `'debug'` when `--debug` flag is enabled
203
+ *
204
+ * 当启用 `--debug` 标志时默认为 `'debug'`
205
+ *
206
+ * @default 'warn'
207
+ */
208
+ logLevel?: 'debug' | 'silent' | 'warn';
209
+ };
210
+ //#endregion
211
+ //#region src/node/markdown/preWrapperPlugin.d.ts
212
+ interface MarkdownItPreWrapperOptions {
213
+ /**
214
+ * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
215
+ * understand what's it for
216
+ *
217
+ * - Required for line numbers, title display and code block collapsing
218
+ */
219
+ preWrapper?: boolean;
220
+ }
221
+ //#endregion
222
+ //#region src/node/options.d.ts
223
+ /**
224
+ * Options of `@vuepress/plugin-shiki`
225
+ *
226
+ * `@vuepress/plugin-shiki` 的选项
227
+ */
228
+ type ShikiPluginOptions = MarkdownItCodeBlockTitleOptions & MarkdownItLineNumbersOptions & MarkdownItPreWrapperOptions & Pick<MarkdownItCollapsedLinesOptions, 'collapsedLines'> & ShikiHighlightOptions & {
229
+ /**
230
+ * Enable twoslash
231
+ *
232
+ * 启用 twoslash
233
+ *
234
+ * @description You should install `@shikijs/twoslash` manually.
235
+ *
236
+ * 你需要手动安装 `@shikijs/twoslash`。
237
+ *
238
+ * @default false
239
+ */
240
+ twoslash?: boolean | (ShikiTwoslashOptions & {
241
+ /**
242
+ * The options for caching resolved types
243
+ *
244
+ * 缓存解析类型的选项
245
+ *
246
+ * @default true
247
+ */
248
+ typesCache?: ShikiTwoslashOptions['typesCache'] | true;
249
+ });
250
+ };
251
+ //#endregion
252
+ //#region src/node/shikiPlugin.d.ts
253
+ /**
254
+ * Shiki plugin for VuePress
255
+ *
256
+ * VuePress 的 Shiki 插件
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * import { shikiPlugin } from '@vuepress/plugin-shiki'
261
+ *
262
+ * export default {
263
+ * plugins: [
264
+ * shikiPlugin({
265
+ * langs: ['ts', 'json', 'vue', 'md', 'bash', 'diff'],
266
+ * theme: 'nord',
267
+ * lineNumbers: true,
268
+ * }),
269
+ * ],
270
+ * }
271
+ * ```
272
+ */
273
+ declare const shikiPlugin: (options?: ShikiPluginOptions) => Plugin;
274
+ //#endregion
275
+ export { ShikiDualThemeOptions, ShikiHighlightOptions, ShikiLang, ShikiPluginOptions, ShikiSingleThemeOptions, ShikiTheme, ShikiThemeOptions, shikiPlugin };
276
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,16 @@
1
+ import{createRequire as e}from"node:module";import{Logger as t,getModulePath as n,isModuleAvailable as r}from"@vuepress/helper";import{codeBlockTitle as i,collapsedLines as a,lineNumbers as o,resolveWhitespacePosition as s}from"@vuepress/highlighter-helper";import{isPlainObject as c}from"vuepress/shared";import{colors as l}from"vuepress/utils";import{createHighlighter as u,isSpecialLang as d}from"shiki";import{createSyncFn as f}from"synckit";import{customAlphabet as p}from"nanoid";import{transformerCompactLineOptions as m,transformerMetaWordHighlight as h,transformerNotationDiff as g,transformerNotationErrorLevel as _,transformerNotationFocus as v,transformerNotationHighlight as y,transformerNotationWordHighlight as b,transformerRemoveComments as x,transformerRenderWhitespace as S}from"@shikijs/transformers";const C=e=>{let t={},n=e.render.bind(e);return e.render=(e,r={})=>(t.path=r.filePathRelative,n(e,r)),()=>t.path||`dynamic pages`},w=/\[\\!code/g,T={name:`vuepress:add-class`,pre(e){this.addClassToHast(e,`vp-code`)}},E={name:`vuepress:cleanup`,pre(e){delete e.properties.tabindex}},D={name:`vuepress:remove-escape`,postprocess:e=>e.replace(w,`[!code`)},O={name:`vuepress:empty-line`,code(e){e.children.forEach(e=>{e.type===`element`&&e.tagName===`span`&&Array.isArray(e.properties.class)&&e.properties.class.includes(`line`)&&e.children.length===0&&e.children.push({type:`element`,tagName:`wbr`,properties:{},children:[]})})}},k={name:`vuepress:v-pre`,pre(e){e.properties[`v-pre`]=``}},A=/-vue$/,j=/\btwoslash\b/,M=`@vuepress/plugin-shiki`,N=new t(M),P=p(`abcdefghijklmnopqrstuvwxyz`,10),F=e=>e.match(/^([^ :[{]+)/)?.[1]?.replace(A,``).toLowerCase()??``,I=e=>{let t=e.match(/\s*[\d,-]*?$/)?.[0].trim(),n=[];return t?(t.split(`,`).map(e=>e.split(`-`).map(e=>Number.parseInt(e,10))).forEach(([e,t])=>{e&&t?n.push(...Array.from({length:t-e+1},(t,n)=>e+n)):n.push(e)}),n.map(e=>({line:e,classes:[`highlighted`]}))):[]},L=f(e(import.meta.url).resolve(`@vuepress/plugin-shiki/resolveLang`)),R=async(e,{langs:t=[],langAlias:n={},defaultLang:r,shikiSetup:i,...a}={},o=!0)=>{let s=await u({langs:[...t,...Object.values(n)],langAlias:n,themes:`themes`in a?Object.values(a.themes):[a.theme??`nord`]}),l=e=>{if(d(e))return!0;if(!s.getLoadedLanguages().includes(e)){let t=L(e);if(t.length===0)return!1;s.loadLanguageSync(t)}return!0},f=s.getLanguage;s.getLanguage=e=>(l(F(typeof e==`string`?e:e.name)),f.call(s,e));let p=[];if(o&&p.push(k),a.twoslash){let{createTwoslashTransformer:t,createFileSystemTypesCache:n}=await import(`@vuepress/shiki-twoslash`),{typesCache:r,...i}=c(a.twoslash)?a.twoslash:{};p.push(await t({...i,typesCache:r===!0||r===void 0?n({dir:e.dir.cache(`markdown/twoslash`)}):r}))}return await i?.(s),{highlighter:s,loadLang:l,extraTransformers:p}},z=e=>{let t=[];return e.notationDiff&&t.push(g()),e.notationFocus&&t.push(v({classActiveLine:`has-focus`,classActivePre:`has-focused-lines`})),e.notationHighlight&&t.push(y()),e.notationErrorLevel&&t.push(_()),e.notationWordHighlight&&(t.push(b()),t.push(h())),e.removeComments&&t.push(x()),t.push(T,E,D,O),t},B=(e,t=!0)=>{let n=s(e,t);return n?[S({position:n})]:[]},V=new Set,H=(e,{defaultLang:t,logLevel:n},r,i)=>{let a=F(e);return a&&!r(a)&&(n!==`silent`&&!V.has(a)&&(N.warn(`Missing ${l.cyan(e)} highlighter, ${t?`use ${l.cyan(t)} to highlight instead.`:`skip highlighting`}`),V.add(a)),n===`debug`&&N.info(`Unknown language ${l.cyan(a)} found in ${l.cyan(i())}`),a=t||`plain`),a},U=/\{\{[^]*?\}\}/g,W=(e,t)=>e.replace(U,e=>{let n=t.get(e);return n||(n=P(),t.set(e,n)),n}),G=(e,t)=>{let n=e;return t.forEach((e,t)=>{n=n.replaceAll(e,t)}),n},K=(e,t)=>{let n=new Map;return G(t(W(e,n).trimEnd()),n)},q=(e,t,n,r,i)=>{let a=z(t);return(o,s,c)=>K(o,o=>e.codeToHtml(o,{lang:H(s,t,r,i),meta:{__raw:c},transformers:[...a,...t.highlightLines??!0?[m(I(c))]:[],...t.whitespace?B(c,t.whitespace):[],...n??[],...t.transformers??[]],...`themes`in t?{themes:t.themes,defaultColor:!1}:{theme:t.theme??`nord`},...t.removeComments?{includeExplanation:`scopeName`}:{}}))},J=/<pre([\s\S]*?)style="([^"]*)"([^>]*)>/,Y=(e,{preWrapper:t=!0}={})=>{let n=e.renderer.rules.fence;e.renderer.rules.fence=(...r)=>{let i=n(...r);if(!i.startsWith(`<pre`))return i;let[a,o,s]=r,c=a[o],l=F(c.info?e.utils.unescapeAll(c.info).trim():``),u=`${s.langPrefix}${l}`;if(i=i.replace(/<code[^]*?>/,`<code class="${u}">`),!t)return i=`<pre class="${u} ${i.slice(12)}`,i;let d=``;return i=i.replace(J,(e,t,n,r)=>(d=n.trim(),`<pre ${t.trim()}${r.trimEnd()}>`)),`<div class="${u}" data-highlighter="shiki" data-ext="${l}" style="${d}">${i}</div>`}},X=/{([\d,-]+?)}/,Z=e=>{let t=e.renderer.rules.fence;e.renderer.rules.fence=(...e)=>{let[n,r]=e,i=n[r],a=i.attrs?.[0],o=null;if(!a){let n=i.info;if(!n||!X.test(n))return t(...e);i.info=n.replace(X,``).trim(),[,o]=X.exec(n)}return!o&&([o]=a,!o||!/[\d,-]+/.test(o))||(i.info+=` ${o}`),t(...e)}},Q=(e,{lineNumbers:t=!0,highlightLines:r=!0,collapsedLines:i=`disable`,codeBlockTitle:a=!0,notationDiff:o,notationErrorLevel:s,notationFocus:c,notationHighlight:l,notationWordHighlight:u,whitespace:d,twoslash:f})=>{let p=[`import "${n(`@vuepress/highlighter-helper/styles/base.css`,import.meta)}"`,`import "${n(`${M}/shiki.css`,import.meta)}"`],m=[],h=[];t!==`disable`&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/line-numbers.css`,import.meta)}"`),(r||l)&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/notation-highlight.css`,import.meta)}"`),o&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/notation-diff.css`,import.meta)}"`),s&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/notation-error-level.css`,import.meta)}"`),c&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/notation-focus.css`,import.meta)}"`),l&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/notation-highlight.css`,import.meta)}"`),u&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/notation-word-highlight.css`,import.meta)}"`),d&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/whitespace.css`,import.meta)}"`),i!==`disable`&&(p.push(`import "${n(`@vuepress/highlighter-helper/styles/collapsed-lines.css`,import.meta)}"`,`import { setupCollapsedLines } from "${n(`@vuepress/highlighter-helper/client`,import.meta)}"`),h.push(`setupCollapsedLines()`)),a&&p.push(`import "${n(`@vuepress/highlighter-helper/styles/code-block-title.css`,import.meta)}"`),f&&(p.push(`import { enhanceTwoslash } from "${n(`@vuepress/shiki-twoslash/client`,import.meta)}"`),p.push(`import "${n(`@vuepress/shiki-twoslash/twoslash.css`,import.meta)}"`),m.push(`enhanceTwoslash(app)`));let g=p.join(`
2
+ `);return(h.length||m.length)&&(g+=`
3
+ export default {
4
+ `,m.length&&(g+=`\
5
+ enhance({ app }) {
6
+ ${m.join(`
7
+ `)}
8
+ },
9
+ `),h.length&&(g+=`\
10
+ setup() {
11
+ ${h.join(`
12
+ `)}
13
+ },
14
+ `),g+=`}
15
+ `),e.writeTemp(`shiki/config.js`,g)},$=(e={})=>t=>{let{code:n}=t.options.markdown,s={...c(n)?n:{},...e};s.logLevel??=t.env.isDebug?`debug`:`warn`,s.preWrapper??=!0,s.lineNumbers??=!0,s.collapsedLines??=`disable`,s.codeBlockTitle??=!0,s.twoslash&&!r(`@vuepress/shiki-twoslash`,import.meta)&&(N.error(`${l.cyan(`twoslash`)} is enabled, but ${l.magenta(`@vuepress/shiki-twoslash`)} is not installed, please install it manually`),s.twoslash=!1);let u=!0;return{name:`@vuepress/plugin-shiki`,extendsMarkdownOptions:e=>{if(e.vPre===!1)u=!1;else{let t=c(e.vPre)?e.vPre:{block:!0};t.block&&(e.vPre??={},e.vPre.block=!1),u=t.block??!0}},extendsMarkdown:async e=>{let{preWrapper:n,lineNumbers:r,collapsedLines:c,codeBlockTitle:l}=s,d=C(e),{highlighter:f,loadLang:p,extraTransformers:m}=await R(t,s,u);e.options.highlight=q(f,s,m,p,d),e.use(Z),e.use(Y,{preWrapper:n}),n&&(e.use(o,{lineNumbers:r,resolveLineNumbers(e){return s.twoslash&&j.test(e)?!1:void 0}}),e.use(a,{collapsedLines:c}),e.use(i,{codeBlockTitle:l}))},clientConfigFile:()=>Q(t,s)}};export{$ as shikiPlugin};
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["lineNumbersPlugin","collapsedLinesPlugin","codeBlockTitlePlugin"],"sources":["../../src/node/markdown/highlighter/createMarkdownFilePathGetter.ts","../../src/node/transformers/vuepressTransformers.ts","../../src/node/utils.ts","../../src/node/markdown/highlighter/createShikiHighlighter.ts","../../src/node/transformers/getTransformers.ts","../../src/node/markdown/highlighter/getLanguage.ts","../../src/node/markdown/highlighter/handleMustache.ts","../../src/node/markdown/highlighter/getHighLightFunction.ts","../../src/node/markdown/preWrapperPlugin.ts","../../src/node/markdown/highlightLinesPlugin.ts","../../src/node/prepareClientConfigFile.ts","../../src/node/shikiPlugin.ts"],"sourcesContent":["import type MarkdownIt from 'markdown-it'\nimport type { MarkdownEnv } from 'vuepress/markdown'\n\n/**\n * Markdown file path getter function type\n *\n * Markdown 文件路径获取器函数类型\n */\nexport type MarkdownFilePathGetter = () => string\n\n/**\n * Create a function to get current markdown file path\n *\n * 创建获取当前 markdown 文件路径的函数\n *\n * @param md - MarkdownIt instance / MarkdownIt 实例\n *\n * @returns Function to get current markdown file path / 获取当前 markdown 文件路径的函数\n */\nexport const createMarkdownFilePathGetter = (\n md: MarkdownIt,\n): MarkdownFilePathGetter => {\n const store: { path?: string | null } = {}\n\n const rawRender = md.render.bind(md)\n\n // we need to store file path before each render\n md.render = (src, env: MarkdownEnv = {}): string => {\n store.path = env.filePathRelative\n\n return rawRender(src, env)\n }\n\n return () => store.path || 'dynamic pages'\n}\n","import type { ShikiTransformer } from 'shiki'\n\nconst CODE_ESCAPE_RE = /\\[\\\\!code/g\n\n/**\n * A transformer to add `vp-code` class to code blocks for better styling\n */\nexport const addClassTransformer: ShikiTransformer = {\n name: 'vuepress:add-class',\n pre(node) {\n this.addClassToHast(node, 'vp-code')\n },\n}\n\n/**\n * A transformer to remove `tabindex` property from code blocks to avoid being focused\n */\nexport const cleanupTransformer: ShikiTransformer = {\n name: 'vuepress:cleanup',\n pre(node) {\n delete node.properties.tabindex\n },\n}\n\n/**\n * This `transformer` is primarily for the usage instructions of themes.\n * When developers need to provide an example like `// [!code xxx]`,\n * they can use `// [\\!code xxx]` to avoid being processed by `shiki`.\n * After `shiki` completes the processing,\n * replace `[\\!code` back with `[!code` to display the correct text.\n */\nexport const removeEscapeTransformer: ShikiTransformer = {\n name: 'vuepress:remove-escape',\n postprocess: (code) => code.replace(CODE_ESCAPE_RE, '[!code'),\n}\n\n/**\n * This transformer adds a `wbr` tag to the end of the empty line to insure the empty line can be correctly displayed\n */\nexport const emptyLineTransformer: ShikiTransformer = {\n name: 'vuepress:empty-line',\n code(hast) {\n hast.children.forEach((span) => {\n if (\n span.type === 'element' &&\n span.tagName === 'span' &&\n Array.isArray(span.properties.class) &&\n span.properties.class.includes('line') &&\n span.children.length === 0\n ) {\n span.children.push({\n type: 'element',\n tagName: 'wbr',\n properties: {},\n children: [],\n })\n }\n })\n },\n}\n\n/**\n * A transformer to add `v-pre` directive to code blocks to avoid being processed by Vue\n */\nexport const vPreTransformer: ShikiTransformer = {\n name: 'vuepress:v-pre',\n pre(node) {\n node.properties['v-pre'] = ''\n },\n}\n","import type { TransformerCompactLineOption } from '@shikijs/transformers'\nimport { Logger } from '@vuepress/helper'\nimport { customAlphabet } from 'nanoid'\n\nconst VUE_RE = /-vue$/\n\nexport const TWOSLASH_RE = /\\btwoslash\\b/\n\nexport const PLUGIN_NAME = '@vuepress/plugin-shiki'\n\nexport const logger = new Logger(PLUGIN_NAME)\n\nexport const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)\n\n/**\n * Resolve language from code fence info string\n *\n * 从代码围栏信息字符串中解析语言\n *\n * @param info - Code fence info string / 代码围栏信息字符串\n *\n * @returns Resolved language / 解析的语言\n */\nexport const resolveLanguage = (info: string): string =>\n info\n .match(/^([^ :[{]+)/)?.[1]\n ?.replace(VUE_RE, '')\n .toLowerCase() ?? ''\n\n/**\n * Convert attributes to line options\n *\n * 将属性转换为行选项\n *\n * @description 2 steps:\n * 1. convert attrs into line numbers:\n * {4,7-13,16,23-27,40} -> [4,7,8,9,10,11,12,13,16,23,24,25,26,27,40]\n * 2. convert line numbers into line options:\n * [{ line: number, classes: string[] }]\n *\n * 转换分为两步:\n * 1. 将属性转换为行号数组\n * 2. 将行号数组转换为行选项\n *\n * @param attrs - Attributes string / 属性字符串\n *\n * @returns Line options array / 行选项数组\n */\nexport const attrsToLines = (attrs: string): TransformerCompactLineOption[] => {\n const attrsContent = attrs.match(/\\s*[\\d,-]*?$/)?.[0].trim()\n const result: number[] = []\n\n if (!attrsContent) return []\n\n attrsContent\n .split(',')\n .map((lineNumberConfig) =>\n lineNumberConfig\n .split('-')\n .map((lineNumber) => Number.parseInt(lineNumber, 10)),\n )\n .forEach(([start, end]) => {\n if (start && end) {\n result.push(\n ...Array.from({ length: end - start + 1 }, (_, i) => start + i),\n )\n } else {\n result.push(start)\n }\n })\n\n return result.map((line) => ({\n line,\n classes: ['highlighted'],\n }))\n}\n","import { createRequire } from 'node:module'\nimport type {\n BundledLanguage,\n BundledTheme,\n HighlighterGeneric,\n ShikiTransformer,\n Grammar,\n} from 'shiki'\nimport { createHighlighter, isSpecialLang } from 'shiki'\nimport { createSyncFn } from 'synckit'\nimport type { App } from 'vuepress'\nimport { isPlainObject } from 'vuepress/shared'\nimport type { ShikiPluginOptions } from '../../options.js'\nimport type { ShikiResolveLang } from '../../resolveLang.js'\nimport { vPreTransformer } from '../../transformers/vuepressTransformers.js'\nimport { resolveLanguage } from '../../utils.js'\n\nconst require = createRequire(import.meta.url)\n\nconst resolveLangSync = createSyncFn<ShikiResolveLang>(\n require.resolve('@vuepress/plugin-shiki/resolveLang'),\n)\n\n/**\n * Load language function type\n *\n * 加载语言函数类型\n */\nexport type ShikiLoadLang = (lang: string) => boolean\n\n/**\n * Create Shiki highlighter with additional features\n *\n * 创建带有额外功能的 Shiki 高亮器\n *\n * @param app - VuePress app instance / VuePress 应用实例\n * @param options - Plugin options / 插件选项\n * @param enableVPre - Whether to enable v-pre transformer / 是否启用 v-pre 转换器\n *\n * @default enableVPre: true\n *\n * @returns Object containing highlighter, loadLang function and extra transformers / 包含高亮器、loadLang 函数和额外转换器的对象\n */\nexport const createShikiHighlighter = async (\n app: App,\n {\n langs = [],\n langAlias = {},\n defaultLang: _,\n shikiSetup,\n ...options\n }: ShikiPluginOptions = {},\n enableVPre = true,\n): Promise<{\n highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>\n loadLang: ShikiLoadLang\n extraTransformers: ShikiTransformer[]\n}> => {\n const highlighter = await createHighlighter({\n langs: [...langs, ...Object.values(langAlias)],\n langAlias,\n themes:\n 'themes' in options\n ? Object.values(options.themes)\n : [options.theme ?? 'nord'],\n })\n\n const loadLang = (lang: string): boolean => {\n if (isSpecialLang(lang)) return true\n\n const loadedLangs = highlighter.getLoadedLanguages()\n\n if (!loadedLangs.includes(lang)) {\n const resolvedLang = resolveLangSync(lang)\n\n if (resolvedLang.length === 0) return false\n\n highlighter.loadLanguageSync(resolvedLang)\n }\n\n return true\n }\n\n // patch for twoslash - https://github.com/vuejs/vitepress/issues/4334\n const rawGetLanguage = highlighter.getLanguage\n\n highlighter.getLanguage = (name): Grammar => {\n const lang = typeof name === 'string' ? name : name.name\n\n loadLang(resolveLanguage(lang))\n\n return rawGetLanguage.call(highlighter, name)\n }\n\n const extraTransformers: ShikiTransformer[] = []\n\n if (enableVPre) extraTransformers.push(vPreTransformer)\n\n if (options.twoslash) {\n const { createTwoslashTransformer, createFileSystemTypesCache } =\n await import('@vuepress/shiki-twoslash')\n\n const { typesCache, ...twoslashOptions } = isPlainObject(options.twoslash)\n ? options.twoslash\n : {}\n\n extraTransformers.push(\n (await createTwoslashTransformer({\n ...twoslashOptions,\n typesCache:\n typesCache === true || typeof typesCache === 'undefined'\n ? createFileSystemTypesCache({\n dir: app.dir.cache('markdown/twoslash'),\n })\n : typesCache,\n // FIXME: We might need to investigate why a type error will be thrown without this type assertion\n // @pengzhanbo\n })) as ShikiTransformer,\n )\n }\n\n await shikiSetup?.(highlighter)\n\n return { highlighter, loadLang, extraTransformers }\n}\n","import {\n transformerMetaWordHighlight,\n transformerNotationDiff,\n transformerNotationErrorLevel,\n transformerNotationFocus,\n transformerNotationHighlight,\n transformerNotationWordHighlight,\n transformerRemoveComments,\n transformerRenderWhitespace,\n} from '@shikijs/transformers'\nimport type { WhitespacePosition } from '@vuepress/highlighter-helper'\nimport { resolveWhitespacePosition } from '@vuepress/highlighter-helper'\nimport type { ShikiTransformer } from 'shiki'\nimport type { ShikiHighlightOptions } from '../types.js'\nimport {\n addClassTransformer,\n cleanupTransformer,\n emptyLineTransformer,\n removeEscapeTransformer,\n} from './vuepressTransformers.js'\n\nexport const getTransformers = (\n options: ShikiHighlightOptions & {\n twoslash?: boolean\n },\n): ShikiTransformer[] => {\n const transformers: ShikiTransformer[] = []\n\n if (options.notationDiff) transformers.push(transformerNotationDiff())\n\n if (options.notationFocus) {\n transformers.push(\n transformerNotationFocus({\n classActiveLine: 'has-focus',\n classActivePre: 'has-focused-lines',\n }),\n )\n }\n\n if (options.notationHighlight)\n transformers.push(transformerNotationHighlight())\n\n if (options.notationErrorLevel)\n transformers.push(transformerNotationErrorLevel())\n\n if (options.notationWordHighlight) {\n transformers.push(transformerNotationWordHighlight())\n transformers.push(transformerMetaWordHighlight())\n }\n\n if (options.removeComments) transformers.push(transformerRemoveComments())\n\n transformers.push(\n addClassTransformer,\n cleanupTransformer,\n removeEscapeTransformer,\n emptyLineTransformer,\n )\n\n return transformers\n}\n\nexport const whitespaceTransformer = (\n meta: string,\n globalOption: WhitespacePosition | true = true,\n): ShikiTransformer[] => {\n const position = resolveWhitespacePosition(meta, globalOption)\n\n return position ? [transformerRenderWhitespace({ position })] : []\n}\n","import { colors } from 'vuepress/utils'\nimport type { ShikiHighlightOptions } from '../../types.js'\nimport { logger, resolveLanguage } from '../../utils.js'\nimport type { MarkdownFilePathGetter } from './createMarkdownFilePathGetter.js'\nimport type { ShikiLoadLang } from './createShikiHighlighter.js'\n\nconst WARNED_LANGS = new Set<string>()\n\nexport const getLanguage = (\n lang: string,\n { defaultLang, logLevel }: ShikiHighlightOptions,\n loadLang: ShikiLoadLang,\n markdownFilePathGetter: MarkdownFilePathGetter,\n): string => {\n let result = resolveLanguage(lang)\n\n if (result && !loadLang(result)) {\n // warn for unknown languages only once\n if (logLevel !== 'silent' && !WARNED_LANGS.has(result)) {\n logger.warn(\n `Missing ${colors.cyan(lang)} highlighter, ${defaultLang ? `use ${colors.cyan(defaultLang)} to highlight instead.` : 'skip highlighting'}`,\n )\n WARNED_LANGS.add(result)\n }\n\n // log file path if unknown language is found\n if (logLevel === 'debug') {\n logger.info(\n `Unknown language ${colors.cyan(result)} found in ${colors.cyan(markdownFilePathGetter())}`,\n )\n }\n\n result = defaultLang || 'plain'\n }\n\n return result\n}\n","import { nanoid } from '../../utils.js'\n\nconst MUSTACHE_REG = /\\{\\{[^]*?\\}\\}/g\n\ntype MustacheStore = Map<string, string>\n\n/**\n * Replace mustache with unique markers\n *\n * @param content original code content\n * @param store mustache store\n * @returns content with mustache replaced by unique markers\n */\nconst removeMustache = (content: string, store: MustacheStore): string =>\n content.replace(MUSTACHE_REG, (match) => {\n let marker = store.get(match)\n\n if (!marker) {\n marker = nanoid()\n store.set(match, marker)\n }\n\n return marker\n })\n\n/**\n * Replace mustache back from unique markers\n *\n * @param content content with unique markers\n * @param store mustache store\n * @returns content with unique markers replaced by original mustache\n */\nconst restoreMustache = (content: string, store: MustacheStore): string => {\n let result = content\n\n store.forEach((marker, match) => {\n result = result.replaceAll(marker, match)\n })\n\n return result\n}\n\n/**\n * Handle mustache in code blocks\n *\n * @description\n * Mustache in code blocks will be replaced with unique markers before highlighting, and restored after highlighting.\n * This is to prevent mustache from being highlighted as code, which may cause issues in some cases.\n *\n * @param content content of code block\n * @param highlight function to highlight content\n * @returns highlighted content with mustache handled\n */\nexport const handleMustache = (\n content: string,\n highlight: (str: string) => string,\n): string => {\n const store = new Map<string, string>()\n\n return restoreMustache(\n highlight(removeMustache(content, store).trimEnd()),\n store,\n )\n}\n","import { transformerCompactLineOptions } from '@shikijs/transformers'\nimport type {\n BundledLanguage,\n BundledTheme,\n HighlighterGeneric,\n ShikiTransformer,\n} from 'shiki'\nimport {\n getTransformers,\n whitespaceTransformer,\n} from '../../transformers/getTransformers.js'\nimport type { ShikiHighlightOptions } from '../../types.js'\nimport { attrsToLines } from '../../utils.js'\nimport type { MarkdownFilePathGetter } from './createMarkdownFilePathGetter.js'\nimport type { ShikiLoadLang } from './createShikiHighlighter.js'\nimport { getLanguage } from './getLanguage.js'\nimport { handleMustache } from './handleMustache.js'\n\ntype MarkdownItHighlight = (\n content: string,\n language: string,\n attrs: string,\n) => string\n\n/**\n * Get highlight function for markdown-it\n *\n * 获取 markdown-it 的高亮函数\n *\n * @param highlighter - Shiki highlighter instance / Shiki 高亮器实例\n * @param options - Highlight options / 高亮选项\n * @param extraTransformers - Extra transformers / 额外转换器\n * @param loadLang - Language loader function / 语言加载函数\n * @param markdownFilePathGetter - Markdown file path getter / Markdown 文件路径获取器\n *\n * @returns Highlight function for markdown-it / markdown-it 的高亮函数\n */\nexport const getHighLightFunction = (\n highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>,\n options: ShikiHighlightOptions,\n extraTransformers: ShikiTransformer[] | undefined,\n loadLang: ShikiLoadLang,\n markdownFilePathGetter: MarkdownFilePathGetter,\n): MarkdownItHighlight => {\n const transformers = getTransformers(options)\n\n return (content, language, attrs) =>\n handleMustache(content, (str) =>\n highlighter.codeToHtml(str, {\n lang: getLanguage(language, options, loadLang, markdownFilePathGetter),\n meta: {\n /**\n * Custom `transformers` passed by users may require `attrs`.\n * e.g. [transformerNotationWordHighlight](https://shiki.style/packages/transformers#transformernotationwordhighlight)\n */\n __raw: attrs,\n },\n transformers: [\n ...transformers,\n ...((options.highlightLines ?? true)\n ? [transformerCompactLineOptions(attrsToLines(attrs))]\n : []),\n ...(options.whitespace\n ? whitespaceTransformer(attrs, options.whitespace)\n : []),\n ...(extraTransformers ?? []),\n ...(options.transformers ?? []),\n ],\n ...('themes' in options\n ? {\n themes: options.themes,\n defaultColor: false,\n }\n : { theme: options.theme ?? 'nord' }),\n ...(options.removeComments\n ? { includeExplanation: 'scopeName' as const }\n : {}),\n }),\n )\n}\n","// markdown-it plugin for generating line numbers.\n// v-pre block logic is in `../highlight.ts`\nimport type { Markdown } from 'vuepress/markdown'\nimport { resolveLanguage } from '../utils.js'\n\nconst PRE_ATTRS_REGEXP = /<pre([\\s\\S]*?)style=\"([^\"]*)\"([^>]*)>/\n\nexport interface MarkdownItPreWrapperOptions {\n /**\n * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you\n * understand what's it for\n *\n * - Required for line numbers, title display and code block collapsing\n */\n preWrapper?: boolean\n}\n\n/**\n * A markdown-it plugin for wrapping `<pre>` tag with an extra `<div>`\n *\n * 一个用于为 `<pre>` 标签添加额外 `<div>` 包装的 markdown-it 插件\n *\n * @param md - MarkdownIt instance / MarkdownIt 实例\n * @param options - Plugin options / 插件选项\n *\n * @default { preWrapper: true }\n */\nexport const preWrapperPlugin = (\n md: Markdown,\n { preWrapper = true }: MarkdownItPreWrapperOptions = {},\n): void => {\n const rawFence = md.renderer.rules.fence!\n\n md.renderer.rules.fence = (...args): string => {\n let result = rawFence(...args)\n\n if (!result.startsWith('<pre')) return result\n\n const [tokens, idx, options] = args\n const token = tokens[idx]\n\n // get token info\n const info = token.info ? md.utils.unescapeAll(token.info).trim() : ''\n\n const lang = resolveLanguage(info)\n const languageClass = `${options.langPrefix}${lang}`\n\n result = result.replace(/<code[^]*?>/, `<code class=\"${languageClass}\">`)\n if (!preWrapper) {\n result = `<pre class=\"${languageClass} ${result.slice('<pre class=\"'.length)}`\n return result\n }\n let styles = ''\n\n // before: maybe `v-pre class=\"shiki *\"`\n // after: style=\"*\" tab-index=\"*\"\n result = result.replace(\n PRE_ATTRS_REGEXP,\n (_, before: string, style: string, after: string) => {\n styles = style.trim()\n // Keep `v-pre class=\"*\"`, remove the rest.\n return `<pre ${before.trim()}${after.trimEnd()}>`\n },\n )\n\n /**\n * Add information to dataset for current code block.\n */\n return `<div class=\"${languageClass}\" data-highlighter=\"shiki\" data-ext=\"${lang}\" style=\"${styles}\">${result}</div>`\n }\n}\n","// Modified from https://github.com/egoist/markdown-it-highlight-lines\n// Now this plugin is only used to normalize line attrs.\n// The else part of line highlights logic is in './highlight.ts'.\n\nimport type { Markdown } from 'vuepress/markdown'\n\nconst HIGHLIGHT_LINES_REGEXP = /{([\\d,-]+?)}/\n\nexport const highlightLinePlugin = (md: Markdown): void => {\n const fence = md.renderer.rules.fence!\n\n md.renderer.rules.fence = (...args): string => {\n const [tokens, idx] = args\n const token = tokens[idx]\n\n // due to use of markdown-it-attrs, the {0} syntax would have been\n // converted to attrs on the token\n const attr = token.attrs?.[0]\n\n let lines: string | null = null\n\n if (!attr) {\n // markdown-it-attrs maybe disabled\n const rawInfo = token.info\n\n if (!rawInfo || !HIGHLIGHT_LINES_REGEXP.test(rawInfo))\n return fence(...args)\n\n const langName = rawInfo.replace(HIGHLIGHT_LINES_REGEXP, '').trim()\n\n // ensure the next plugin get the correct lang\n token.info = langName\n\n ;[, lines] = HIGHLIGHT_LINES_REGEXP.exec(rawInfo)!\n }\n\n if (!lines) {\n ;[lines] = attr!\n\n if (!lines || !/[\\d,-]+/.test(lines)) return fence(...args)\n }\n\n token.info += ` ${lines}`\n return fence(...args)\n }\n}\n","import { getModulePath } from '@vuepress/helper'\nimport type { App } from 'vuepress'\nimport type { ShikiPluginOptions } from './options.js'\nimport { PLUGIN_NAME } from './utils.js'\n\n// oxlint-disable-next-line max-lines-per-function, complexity, max-statements\nexport const prepareClientConfigFile = (\n app: App,\n {\n lineNumbers = true,\n highlightLines = true,\n collapsedLines = 'disable',\n codeBlockTitle = true,\n notationDiff,\n notationErrorLevel,\n notationFocus,\n notationHighlight,\n notationWordHighlight,\n whitespace,\n twoslash,\n }: ShikiPluginOptions,\n): Promise<string> => {\n const imports: string[] = [\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/base.css', import.meta)}\"`,\n `import \"${getModulePath(`${PLUGIN_NAME}/shiki.css`, import.meta)}\"`,\n ]\n\n const enhances: string[] = []\n const setups: string[] = []\n\n if (lineNumbers !== 'disable') {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/line-numbers.css', import.meta)}\"`,\n )\n }\n\n if (highlightLines || notationHighlight) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-highlight.css', import.meta)}\"`,\n )\n }\n\n if (notationDiff) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-diff.css', import.meta)}\"`,\n )\n }\n\n if (notationErrorLevel) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-error-level.css', import.meta)}\"`,\n )\n }\n\n if (notationFocus) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-focus.css', import.meta)}\"`,\n )\n }\n\n if (notationHighlight) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-highlight.css', import.meta)}\"`,\n )\n }\n\n if (notationWordHighlight) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-word-highlight.css', import.meta)}\"`,\n )\n }\n\n if (whitespace) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/whitespace.css', import.meta)}\"`,\n )\n }\n\n if (collapsedLines !== 'disable') {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/collapsed-lines.css', import.meta)}\"`,\n `import { setupCollapsedLines } from \"${getModulePath('@vuepress/highlighter-helper/client', import.meta)}\"`,\n )\n setups.push('setupCollapsedLines()')\n }\n\n if (codeBlockTitle) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/code-block-title.css', import.meta)}\"`,\n )\n }\n\n if (twoslash) {\n imports.push(\n `import { enhanceTwoslash } from \"${getModulePath('@vuepress/shiki-twoslash/client', import.meta)}\"`,\n )\n imports.push(\n `import \"${getModulePath('@vuepress/shiki-twoslash/twoslash.css', import.meta)}\"`,\n )\n enhances.push('enhanceTwoslash(app)')\n }\n\n let code = imports.join('\\n')\n\n if (setups.length || enhances.length) {\n code += `\nexport default {\n`\n\n if (enhances.length) {\n code += `\\\n enhance({ app }) {\n ${enhances.join('\\n ')}\n },\n`\n }\n\n if (setups.length) {\n code += `\\\n setup() {\n ${setups.join('\\n ')}\n },\n`\n }\n\n code += `\\\n}\n`\n }\n\n return app.writeTemp('shiki/config.js', code)\n}\n","import { isModuleAvailable } from '@vuepress/helper'\nimport type {\n MarkdownItCodeBlockTitleOptions,\n MarkdownItCollapsedLinesOptions,\n MarkdownItLineNumbersOptions,\n} from '@vuepress/highlighter-helper'\nimport {\n codeBlockTitle as codeBlockTitlePlugin,\n collapsedLines as collapsedLinesPlugin,\n lineNumbers as lineNumbersPlugin,\n} from '@vuepress/highlighter-helper'\nimport type { Plugin } from 'vuepress/core'\nimport { isPlainObject } from 'vuepress/shared'\nimport { colors } from 'vuepress/utils'\nimport { createMarkdownFilePathGetter } from './markdown/highlighter/createMarkdownFilePathGetter.js'\nimport type { MarkdownItPreWrapperOptions } from './markdown/index.js'\nimport {\n createShikiHighlighter,\n getHighLightFunction,\n highlightLinePlugin,\n preWrapperPlugin,\n} from './markdown/index.js'\nimport type { ShikiPluginOptions } from './options.js'\nimport { prepareClientConfigFile } from './prepareClientConfigFile.js'\nimport { TWOSLASH_RE, logger } from './utils.js'\n\n/**\n * Shiki plugin for VuePress\n *\n * VuePress 的 Shiki 插件\n *\n * @example\n * ```ts\n * import { shikiPlugin } from '@vuepress/plugin-shiki'\n *\n * export default {\n * plugins: [\n * shikiPlugin({\n * langs: ['ts', 'json', 'vue', 'md', 'bash', 'diff'],\n * theme: 'nord',\n * lineNumbers: true,\n * }),\n * ],\n * }\n * ```\n */\nexport const shikiPlugin =\n (options: ShikiPluginOptions = {}): Plugin =>\n (app) => {\n // TODO: Remove in stable version\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const { code } = app.options.markdown\n const shikiOptions = {\n ...(isPlainObject(code) ? code : {}),\n ...options,\n }\n\n shikiOptions.logLevel ??= app.env.isDebug ? 'debug' : 'warn'\n shikiOptions.preWrapper ??= true\n shikiOptions.lineNumbers ??= true\n shikiOptions.collapsedLines ??= 'disable'\n shikiOptions.codeBlockTitle ??= true\n\n if (\n shikiOptions.twoslash &&\n !isModuleAvailable('@vuepress/shiki-twoslash', import.meta)\n ) {\n logger.error(\n `${colors.cyan('twoslash')} is enabled, but ${colors.magenta('@vuepress/shiki-twoslash')} is not installed, please install it manually`,\n )\n shikiOptions.twoslash = false\n }\n\n /**\n * Whether to enable the `v-pre` configuration of the code block\n */\n let enableVPre = true\n\n return {\n name: '@vuepress/plugin-shiki',\n\n extendsMarkdownOptions: (opts) => {\n /**\n * Turn off the `v-pre` configuration of the code block.\n */\n if (opts.vPre === false) {\n enableVPre = false\n } else {\n const vPre = isPlainObject(opts.vPre) ? opts.vPre : { block: true }\n if (vPre.block) {\n opts.vPre ??= {}\n opts.vPre.block = false\n }\n enableVPre = vPre.block ?? true\n }\n },\n\n extendsMarkdown: async (md) => {\n const { preWrapper, lineNumbers, collapsedLines, codeBlockTitle } =\n shikiOptions\n\n const markdownFilePathGetter = createMarkdownFilePathGetter(md)\n const { highlighter, loadLang, extraTransformers } =\n await createShikiHighlighter(app, shikiOptions, enableVPre)\n\n md.options.highlight = getHighLightFunction(\n highlighter,\n shikiOptions,\n extraTransformers,\n loadLang,\n markdownFilePathGetter,\n )\n md.use(highlightLinePlugin)\n md.use<MarkdownItPreWrapperOptions>(preWrapperPlugin, { preWrapper })\n if (preWrapper) {\n md.use<MarkdownItLineNumbersOptions>(lineNumbersPlugin, {\n lineNumbers,\n resolveLineNumbers(info) {\n return shikiOptions.twoslash && TWOSLASH_RE.test(info)\n ? false\n : undefined\n },\n })\n md.use<MarkdownItCollapsedLinesOptions>(collapsedLinesPlugin, {\n collapsedLines,\n })\n md.use<MarkdownItCodeBlockTitleOptions>(codeBlockTitlePlugin, {\n codeBlockTitle,\n })\n }\n },\n\n clientConfigFile: () => prepareClientConfigFile(app, shikiOptions),\n }\n }\n"],"mappings":"ozBAmBA,MAAa,EACX,GAC2B,CAC3B,IAAM,EAAkC,EAAE,CAEpC,EAAY,EAAG,OAAO,KAAK,EAAG,CASpC,MANA,GAAG,QAAU,EAAK,EAAmB,EAAE,IACrC,EAAM,KAAO,EAAI,iBAEV,EAAU,EAAK,EAAI,MAGf,EAAM,MAAQ,iBC/BvB,EAAiB,aAKV,EAAwC,CACnD,KAAM,qBACN,IAAI,EAAM,CACR,KAAK,eAAe,EAAM,UAAU,EAEvC,CAKY,EAAuC,CAClD,KAAM,mBACN,IAAI,EAAM,C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AmB,UAChC,EAAa,iBAAmB,GAG9B,EAAa,UACb,CAAC,EAAkB,2BAA4B,OAAO,KAAK,GAE3D,EAAO,MACL,GAAG,EAAO,KAAK,WAAW,CAAC,mBAAmB,EAAO,QAAQ,2BAA2B,CAAC,+CAC1F,CACD,EAAa,SAAW,IAM1B,IAAI,EAAa,GAEjB,MAAO,CACL,KAAM,yBAEN,uBAAyB,GAAS,CAIhC,GAAI,EAAK,OAAS,GAChB,EAAa,OACR,CACL,IAAM,EAAO,EAAc,EAAK,KAAK,CAAG,EAAK,KAAO,CAAE,MAAO,GAAM,CAC/D,EAAK,QACP,EAAK,OAAS,EAAE,CAChB,EAAK,KAAK,MAAQ,IAEpB,EAAa,EAAK,OAAS,KAI/B,gBAAiB,KAAO,IAAO,CAC7B,GAAM,CAAE,aAAY,YAAA,EAAa,eAAA,EAAgB,eAAA,GAC/C,EAEI,EAAyB,EAA6B,EAAG,CACzD,CAAE,cAAa,WAAU,qBAC7B,MAAM,EAAuB,EAAK,EAAc,EAAW,CAE7D,EAAG,QAAQ,UAAY,EACrB,EACA,EACA,EACA,EACA,EACD,CACD,EAAG,IAAI,EAAoB,CAC3B,EAAG,IAAiC,EAAkB,CAAE,aAAY,CAAC,CACjE,IACF,EAAG,IAAkCA,EAAmB,CACtD,YAAA,EACA,mBAAmB,EAAM,CACvB,OAAO,EAAa,UAAY,EAAY,KAAK,EAAK,CAClD,GACA,IAAA,IAEP,CAAC,CACF,EAAG,IAAqCC,EAAsB,CAC5D,eAAA,EACD,CAAC,CACF,EAAG,IAAqCC,EAAsB,CAC5D,eAAA,EACD,CAAC,GAIN,qBAAwB,EAAwB,EAAK,EAAa,CACnE"}
@@ -0,0 +1,8 @@
1
+ import { LanguageRegistration } from "shiki";
2
+
3
+ //#region src/node/resolveLang.d.ts
4
+ declare const resolveLang: (lang: string) => Promise<LanguageRegistration[]>;
5
+ type ShikiResolveLang = typeof resolveLang;
6
+ //#endregion
7
+ export { ShikiResolveLang };
8
+ //# sourceMappingURL=resolveLang.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{bundledLanguages as e}from"shiki";import{runAsWorker as t}from"synckit";t(async t=>e[t]?.().then(e=>e.default)??[]);export{};
2
+ //# sourceMappingURL=resolveLang.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLang.js","names":[],"sources":["../../src/node/resolveLang.ts"],"sourcesContent":["// oxlint-disable no-unexpected-multiline\nimport type {\n DynamicImportLanguageRegistration,\n LanguageRegistration,\n} from 'shiki'\nimport { bundledLanguages } from 'shiki'\nimport { runAsWorker } from 'synckit'\n\nconst resolveLang = async (lang: string): Promise<LanguageRegistration[]> =>\n (\n bundledLanguages as Record<\n string,\n DynamicImportLanguageRegistration | undefined\n >\n )\n [lang]?.()\n .then((mod) => mod.default) ?? []\n\nrunAsWorker(resolveLang)\n\nexport type ShikiResolveLang = typeof resolveLang\n"],"mappings":"+EAkBA,EAVoB,KAAO,IAEvB,EAKC,MAAS,CACT,KAAM,GAAQ,EAAI,QAAQ,EAAI,EAAE,CAEb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/plugin-shiki",
3
- "version": "2.0.0-rc.123",
3
+ "version": "2.0.0-rc.125",
4
4
  "description": "VuePress plugin - shiki",
5
5
  "keywords": [
6
6
  "highlight",
@@ -21,35 +21,41 @@
21
21
  "directory": "plugins/markdown/plugin-shiki"
22
22
  },
23
23
  "files": [
24
- "lib"
24
+ "dist"
25
25
  ],
26
26
  "type": "module",
27
- "main": "./lib/node/index.js",
28
- "types": "./lib/node/index.d.ts",
27
+ "sideEffects": [
28
+ "./dist/client/styles/**/*.css"
29
+ ],
30
+ "main": "./dist/node/index.js",
31
+ "types": "./dist/node/index.d.ts",
29
32
  "exports": {
30
- ".": "./lib/node/index.js",
31
- "./resolveLang": "./lib/node/resolveLang.js",
32
- "./styles/*": "./lib/client/styles/*",
33
+ ".": {
34
+ "types": "./dist/node/index.d.ts",
35
+ "default": "./dist/node/index.js"
36
+ },
37
+ "./resolveLang": "./dist/node/resolveLang.js",
38
+ "./shiki.css": "./dist/client/styles/shiki.css",
33
39
  "./package.json": "./package.json"
34
40
  },
35
41
  "publishConfig": {
36
42
  "access": "public"
37
43
  },
38
44
  "dependencies": {
39
- "@shikijs/transformers": "^3.22.0",
40
- "@vuepress/helper": "2.0.0-rc.123",
41
- "@vuepress/highlighter-helper": "2.0.0-rc.123",
45
+ "@shikijs/transformers": "^4.0.1",
46
+ "@vuepress/helper": "2.0.0-rc.125",
47
+ "@vuepress/highlighter-helper": "2.0.0-rc.125",
42
48
  "nanoid": "^5.1.6",
43
- "shiki": "^3.22.0",
49
+ "shiki": "^4.0.1",
44
50
  "synckit": "^0.11.12"
45
51
  },
46
52
  "devDependencies": {
47
53
  "@types/markdown-it": "^14.1.2",
48
- "@vuepress/shiki-twoslash": "2.0.0-rc.123",
54
+ "@vuepress/shiki-twoslash": "2.0.0-rc.125",
49
55
  "markdown-it": "^14.1.1"
50
56
  },
51
57
  "peerDependencies": {
52
- "@vuepress/shiki-twoslash": "2.0.0-rc.123",
58
+ "@vuepress/shiki-twoslash": "2.0.0-rc.125",
53
59
  "vuepress": "2.0.0-rc.26"
54
60
  },
55
61
  "peerDependenciesMeta": {
@@ -57,5 +63,5 @@
57
63
  "optional": true
58
64
  }
59
65
  },
60
- "gitHead": "4d944d5826c6ed0487caa973516f9db0194dc934"
66
+ "gitHead": "58e660bb7138f1883e5440a08903d09cdbabcdc8"
61
67
  }
@@ -1,260 +0,0 @@
1
- import { WhitespacePosition, MarkdownItCodeBlockTitleOptions, MarkdownItLineNumbersOptions, MarkdownItCollapsedLinesOptions } from '@vuepress/highlighter-helper';
2
- import { ShikiTwoslashOptions } from '@vuepress/shiki-twoslash';
3
- import { StringLiteralUnion, BundledTheme, ThemeRegistrationAny, LanguageInput, SpecialLanguage, BundledLanguage, Highlighter, ShikiTransformer } from 'shiki';
4
- import { Plugin } from 'vuepress/core';
5
-
6
- /**
7
- * Shiki language type
8
- *
9
- * Shiki 语言类型
10
- */
11
- type ShikiLang = LanguageInput | SpecialLanguage | StringLiteralUnion<BundledLanguage>;
12
- /**
13
- * Shiki theme type
14
- *
15
- * Shiki 主题类型
16
- */
17
- type ShikiTheme = StringLiteralUnion<BundledTheme> | ThemeRegistrationAny;
18
- /**
19
- * Single theme options for Shiki
20
- *
21
- * Shiki 单主题配置
22
- */
23
- interface ShikiSingleThemeOptions {
24
- /**
25
- * The single theme to use
26
- *
27
- * @see https://shiki.style/themes
28
- *
29
- * @default 'nord'
30
- */
31
- theme?: ShikiTheme;
32
- }
33
- /**
34
- * Dual theme options for Shiki
35
- *
36
- * Shiki 双主题配置
37
- */
38
- interface ShikiDualThemeOptions {
39
- /**
40
- * The dark and light themes to use
41
- *
42
- * @see https://shiki.style/themes
43
- */
44
- themes: {
45
- dark: ShikiTheme;
46
- light: ShikiTheme;
47
- };
48
- }
49
- /**
50
- * Shiki theme options
51
- *
52
- * Shiki 主题配置选项
53
- */
54
- type ShikiThemeOptions = ShikiDualThemeOptions | ShikiSingleThemeOptions;
55
- /**
56
- * Shiki highlight options
57
- *
58
- * Shiki 高亮配置选项
59
- */
60
- type ShikiHighlightOptions = ShikiThemeOptions & {
61
- /**
62
- * Languages to be loaded.
63
- *
64
- * Shiki does not preload any languages to avoid extra overhead. So you need
65
- * to specify the languages you want to use.
66
- *
67
- * 要加载的语言。
68
- *
69
- * Shiki 不会预加载任何语言以避免额外开销。所以你需要指定要使用的语言。
70
- *
71
- * @see https://shiki.style/languages
72
- */
73
- langs?: ShikiLang[];
74
- /**
75
- * Language alias
76
- *
77
- * 语言别名
78
- *
79
- * @see https://shiki.style/guide/load-lang#custom-language-aliases
80
- */
81
- langAlias?: Record<string, StringLiteralUnion<BundledLanguage>>;
82
- /**
83
- * Fallback language when the specified language is not available.
84
- *
85
- * 指定语言不可用时的备选语言。
86
- *
87
- * @default 'plain'
88
- */
89
- defaultLang?: string;
90
- /**
91
- * Function to customize Shiki highlighter instance.
92
- *
93
- * 自定义 Shiki 高亮器实例的函数。
94
- */
95
- shikiSetup?: (shiki: Highlighter) => Promise<void> | void;
96
- /**
97
- * Shiki transformers
98
- *
99
- * Shiki 转换器
100
- */
101
- transformers?: ShikiTransformer[];
102
- /**
103
- * Enable highlight lines or not
104
- *
105
- * 是否启用行高亮
106
- *
107
- * @default true
108
- */
109
- highlightLines?: boolean;
110
- /**
111
- * Enable notation diff transformer
112
- *
113
- * 是否启用差异标记转换器
114
- *
115
- * @default false
116
- *
117
- * @see https://shiki.style/packages/transformers#transformernotationdiff
118
- */
119
- notationDiff?: boolean;
120
- /**
121
- * Enable notation focus transformer
122
- *
123
- * 是否启用聚焦标记转换器
124
- *
125
- * @default false
126
- *
127
- * @see https://shiki.style/packages/transformers#transformernotationfocus
128
- */
129
- notationFocus?: boolean;
130
- /**
131
- * Enable notation highlight transformer
132
- *
133
- * 是否启用高亮标记转换器
134
- *
135
- * @default false
136
- *
137
- * @see https://shiki.style/packages/transformers#transformernotationhighlight
138
- */
139
- notationHighlight?: boolean;
140
- /**
141
- * Enable notation error level transformer
142
- *
143
- * 是否启用错误级别标记转换器
144
- *
145
- * @default false
146
- *
147
- * @see https://shiki.style/packages/transformers#transformernotationerrorlevel
148
- */
149
- notationErrorLevel?: boolean;
150
- /**
151
- * Enable notation word highlight transformer
152
- *
153
- * 是否启用单词高亮标记转换器
154
- *
155
- * @default false
156
- *
157
- * @see https://shiki.style/packages/transformers#transformernotationwordhighlight
158
- */
159
- notationWordHighlight?: boolean;
160
- /**
161
- * Enable whitespace
162
- * - true: enable whitespace, but not render any whitespace by default
163
- * - false: disable whitespace completely
164
- * - 'all': render all whitespace
165
- * - 'boundary': render leading and trailing whitespace of each line.
166
- * - 'trailing': render trailing whitespace of each line
167
- *
168
- * you are able to use `:whitespace` or `:no-whitespace` or `:whitespace=all|boundary|trailing` to set single code block
169
- *
170
- * 启用空白字符显示
171
- * - true: 启用空白字符,但默认不渲染任何空白字符
172
- * - false: 完全禁用空白字符
173
- * - 'all': 渲染所有空白字符
174
- * - 'boundary': 渲染每行的前导和尾随空白字符
175
- * - 'trailing': 渲染每行的尾随空白字符
176
- *
177
- * 你可以使用 `:whitespace` 或 `:no-whitespace` 或 `:whitespace=all|boundary|trailing` 来设置单个代码块
178
- *
179
- * @default false
180
- *
181
- * @see https://shiki.style/packages/transformers#transformerrenderwhitespace
182
- */
183
- whitespace?: WhitespacePosition | boolean;
184
- /**
185
- * Log level Highlighter language detecter
186
- *
187
- * 高亮器语言检测器的日志级别
188
- *
189
- * @description defaults to `'debug'` when `--debug` flag is enabled
190
- *
191
- * 当启用 `--debug` 标志时默认为 `'debug'`
192
- *
193
- * @default 'warn'
194
- */
195
- logLevel?: 'debug' | 'silent' | 'warn';
196
- };
197
-
198
- interface MarkdownItPreWrapperOptions {
199
- /**
200
- * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
201
- * understand what's it for
202
- *
203
- * - Required for line numbers, title display and code block collapsing
204
- */
205
- preWrapper?: boolean;
206
- }
207
-
208
- /**
209
- * Options of `@vuepress/plugin-shiki`
210
- *
211
- * `@vuepress/plugin-shiki` 的选项
212
- */
213
- type ShikiPluginOptions = MarkdownItCodeBlockTitleOptions & MarkdownItLineNumbersOptions & MarkdownItPreWrapperOptions & Pick<MarkdownItCollapsedLinesOptions, 'collapsedLines'> & ShikiHighlightOptions & {
214
- /**
215
- * Enable twoslash
216
- *
217
- * 启用 twoslash
218
- *
219
- * @description You should install `@shikijs/twoslash` manually.
220
- *
221
- * 你需要手动安装 `@shikijs/twoslash`。
222
- *
223
- * @default false
224
- */
225
- twoslash?: boolean | (ShikiTwoslashOptions & {
226
- /**
227
- * The options for caching resolved types
228
- *
229
- * 缓存解析类型的选项
230
- *
231
- * @default true
232
- */
233
- typesCache?: ShikiTwoslashOptions['typesCache'] | true;
234
- });
235
- };
236
-
237
- /**
238
- * Shiki plugin for VuePress
239
- *
240
- * VuePress 的 Shiki 插件
241
- *
242
- * @example
243
- * ```ts
244
- * import { shikiPlugin } from '@vuepress/plugin-shiki'
245
- *
246
- * export default {
247
- * plugins: [
248
- * shikiPlugin({
249
- * langs: ['ts', 'json', 'vue', 'md', 'bash', 'diff'],
250
- * theme: 'nord',
251
- * lineNumbers: true,
252
- * }),
253
- * ],
254
- * }
255
- * ```
256
- */
257
- declare const shikiPlugin: (options?: ShikiPluginOptions) => Plugin;
258
-
259
- export { shikiPlugin };
260
- export type { ShikiDualThemeOptions, ShikiHighlightOptions, ShikiLang, ShikiPluginOptions, ShikiSingleThemeOptions, ShikiTheme, ShikiThemeOptions };
package/lib/node/index.js DELETED
@@ -1,14 +0,0 @@
1
- import{Logger as P,getModulePath as c,isModuleAvailable as N}from"@vuepress/helper";import{resolveWhitespacePosition as A,lineNumbers as C,collapsedLines as H,codeBlockTitle as W}from"@vuepress/highlighter-helper";import{isPlainObject as w}from"vuepress/shared";import{colors as v}from"vuepress/utils";import{customAlphabet as x}from"nanoid";import{createRequire as E}from"node:module";import{createHighlighter as M,isSpecialLang as S}from"shiki";import{createSyncFn as F}from"synckit";import{transformerNotationDiff as j,transformerNotationFocus as O,transformerNotationHighlight as B,transformerNotationErrorLevel as D,transformerNotationWordHighlight as R,transformerMetaWordHighlight as _,transformerRenderWhitespace as q,transformerCompactLineOptions as G}from"@shikijs/transformers";const I=t=>{const e={},i=t.render.bind(t);return t.render=(s,o={})=>(e.path=o.filePathRelative,i(s,o)),()=>e.path||"dynamic pages"},U=/\[\\!code/g,z={name:"vuepress:add-class",pre(t){this.addClassToHast(t,"vp-code")}},J={name:"vuepress:cleanup",pre(t){delete t.properties.tabindex}},K={name:"vuepress:remove-escape",postprocess:t=>t.replace(U,"[!code")},Q={name:"vuepress:empty-line",code(t){t.children.forEach(e=>{e.type==="element"&&e.tagName==="span"&&Array.isArray(e.properties.class)&&e.properties.class.includes("line")&&e.children.length===0&&e.children.push({type:"element",tagName:"wbr",properties:{},children:[]})})}},V={name:"vuepress:v-pre",pre(t){t.properties["v-pre"]=""}},X=/-vue$/,Y=/\btwoslash\b/,b="@vuepress/plugin-shiki",$=new P(b),Z=x("abcdefghijklmnopqrstuvwxyz",10),y=t=>t.match(/^([^ :[{]+)/)?.[1]?.replace(X,"").toLowerCase()??"",ee=t=>{const e=t.match(/\s*[\d,-]*?$/)?.[0].trim(),i=[];return e?(e.split(",").map(s=>s.split("-").map(o=>Number.parseInt(o,10))).forEach(([s,o])=>{s&&o?i.push(...Array.from({length:o-s+1},(r,h)=>s+h)):i.push(s)}),i.map(s=>({line:s,classes:["highlighted"]}))):[]},te=E(import.meta.url),se=F(te.resolve("@vuepress/plugin-shiki/resolveLang")),re=async(t,{langs:e=[],langAlias:i={},defaultLang:s,shikiSetup:o,...r}={},h=!0)=>{const a=await M({langs:[...e,...Object.values(i)],langAlias:i,themes:"themes"in r?Object.values(r.themes):[r.theme??"nord"]}),l=p=>{if(S(p))return!0;if(!a.getLoadedLanguages().includes(p)){const n=se(p);if(n.length===0)return!1;a.loadLanguageSync(n)}return!0},u=a.getLanguage;a.getLanguage=p=>{const n=typeof p=="string"?p:p.name;return l(y(n)),u.call(a,p)};const g=[];if(h&&g.push(V),r.twoslash){const{createTwoslashTransformer:p,createFileSystemTypesCache:n}=await import("@vuepress/shiki-twoslash"),{typesCache:m,...d}=w(r.twoslash)?r.twoslash:{};g.push(await p({...d,typesCache:m===!0||typeof m>"u"?n({dir:t.dir.cache("markdown/twoslash")}):m}))}return await o?.(a),{highlighter:a,loadLang:l,extraTransformers:g}},ie=t=>{const e=[];return t.notationDiff&&e.push(j()),t.notationFocus&&e.push(O({classActiveLine:"has-focus",classActivePre:"has-focused-lines"})),t.notationHighlight&&e.push(B()),t.notationErrorLevel&&e.push(D()),t.notationWordHighlight&&(e.push(R()),e.push(_())),e.push(z,J,K,Q),e},oe=(t,e=!0)=>{const i=A(t,e);return i?[q({position:i})]:[]},k=new Set,ne=(t,{defaultLang:e,logLevel:i},s,o)=>{let r=y(t);return r&&!s(r)&&(i!=="silent"&&!k.has(r)&&($.warn(`Missing ${v.cyan(t)} highlighter, ${e?`use ${v.cyan(e)} to highlight instead.`:"skip highlighting"}`),k.add(r)),i==="debug"&&$.info(`Unknown language ${v.cyan(r)} found in ${v.cyan(o())}`),r=e||"plain"),r},ae=/\{\{[^]*?\}\}/g,le=(t,e)=>t.replace(ae,i=>{let s=e.get(i);return s||(s=Z(),e.set(i,s)),s}),he=(t,e)=>{let i=t;return e.forEach((s,o)=>{i=i.replaceAll(s,o)}),i},pe=(t,e)=>{const i=new Map;return he(e(le(t,i).trimEnd()),i)},ce=(t,e,i,s,o)=>{const r=ie(e);return(h,a,l)=>pe(h,u=>t.codeToHtml(u,{lang:ne(a,e,s,o),meta:{__raw:l},transformers:[...r,...e.highlightLines??!0?[G(ee(l))]:[],...e.whitespace?oe(l,e.whitespace):[],...i??[],...e.transformers??[]],..."themes"in e?{themes:e.themes,defaultColor:!1}:{theme:e.theme??"nord"}}))},ue=/<pre([\s\S]*?)style="([^"]*)"([^>]*)>/,me=(t,{preWrapper:e=!0}={})=>{const i=t.renderer.rules.fence;t.renderer.rules.fence=(...s)=>{let o=i(...s);if(!o.startsWith("<pre"))return o;const[r,h,a]=s,l=r[h],u=l.info?t.utils.unescapeAll(l.info).trim():"",g=y(u),p=`${a.langPrefix}${g}`;if(o=o.replace(/<code[^]*?>/,`<code class="${p}">`),!e)return o=`<pre class="${p} ${o.slice(12)}`,o;let n="";return o=o.replace(ue,(m,d,f,T)=>(n=f.trim(),`<pre ${d.trim()}${T.trimEnd()}>`)),`<div class="${p}" data-highlighter="shiki" data-ext="${g}" style="${n}">${o}</div>`}},L=/{([\d,-]+?)}/,ge=t=>{const e=t.renderer.rules.fence;t.renderer.rules.fence=(...i)=>{const[s,o]=i,r=s[o],h=r.attrs?.[0];let a=null;if(!h){const l=r.info;if(!l||!L.test(l))return e(...i);const u=l.replace(L,"").trim();r.info=u,[,a]=L.exec(l)}return!a&&([a]=h,!a||!/[\d,-]+/.test(a))?e(...i):(r.info+=` ${a}`,e(...i))}},de=(t,{lineNumbers:e=!0,highlightLines:i=!0,collapsedLines:s="disable",codeBlockTitle:o=!0,notationDiff:r,notationErrorLevel:h,notationFocus:a,notationHighlight:l,notationWordHighlight:u,whitespace:g,twoslash:p})=>{const n=[`import "${c("@vuepress/highlighter-helper/styles/base.css",import.meta)}"`,`import "${c(`${b}/styles/shiki.css`,import.meta)}"`],m=[],d=[];e!=="disable"&&n.push(`import "${c("@vuepress/highlighter-helper/styles/line-numbers.css",import.meta)}"`),(i||l)&&n.push(`import "${c("@vuepress/highlighter-helper/styles/notation-highlight.css",import.meta)}"`),r&&n.push(`import "${c("@vuepress/highlighter-helper/styles/notation-diff.css",import.meta)}"`),h&&n.push(`import "${c("@vuepress/highlighter-helper/styles/notation-error-level.css",import.meta)}"`),a&&n.push(`import "${c("@vuepress/highlighter-helper/styles/notation-focus.css",import.meta)}"`),l&&n.push(`import "${c("@vuepress/highlighter-helper/styles/notation-highlight.css",import.meta)}"`),u&&n.push(`import "${c("@vuepress/highlighter-helper/styles/notation-word-highlight.css",import.meta)}"`),g&&n.push(`import "${c("@vuepress/highlighter-helper/styles/whitespace.css",import.meta)}"`),s!=="disable"&&(n.push(`import "${c("@vuepress/highlighter-helper/styles/collapsed-lines.css",import.meta)}"`,`import { setupCollapsedLines } from "${c("@vuepress/highlighter-helper/client",import.meta)}"`),d.push("setupCollapsedLines()")),o&&n.push(`import "${c("@vuepress/highlighter-helper/styles/code-block-title.css",import.meta)}"`),p&&(n.push(`import { enhanceTwoslash } from "${c("@vuepress/shiki-twoslash/client",import.meta)}"`),n.push(`import "${c("@vuepress/shiki-twoslash/styles/twoslash.css",import.meta)}"`),m.push("enhanceTwoslash(app)"));let f=n.join(`
2
- `);return(d.length||m.length)&&(f+=`
3
- export default {
4
- `,m.length&&(f+=` enhance({ app }) {
5
- ${m.join(`
6
- `)}
7
- },
8
- `),d.length&&(f+=` setup() {
9
- ${d.join(`
10
- `)}
11
- },
12
- `),f+=`}
13
- `),t.writeTemp("shiki/config.js",f)},fe=(t={})=>e=>{const{code:i}=e.options.markdown,s={...w(i)?i:{},...t};s.logLevel??=e.env.isDebug?"debug":"warn",s.preWrapper??=!0,s.lineNumbers??=!0,s.collapsedLines??="disable",s.codeBlockTitle??=!0,s.twoslash&&!N("@vuepress/shiki-twoslash",import.meta)&&($.error(`${v.cyan("twoslash")} is enabled, but ${v.magenta("@vuepress/shiki-twoslash")} is not installed, please install it manually`),s.twoslash=!1);let o=!0;return{name:"@vuepress/plugin-shiki",extendsMarkdownOptions:r=>{if(r.vPre===!1)o=!1;else{const h=w(r.vPre)?r.vPre:{block:!0};h.block&&(r.vPre??={},r.vPre.block=!1),o=h.block??!0}},extendsMarkdown:async r=>{const{preWrapper:h,lineNumbers:a,collapsedLines:l,codeBlockTitle:u}=s,g=I(r),{highlighter:p,loadLang:n,extraTransformers:m}=await re(e,s,o);r.options.highlight=ce(p,s,m,n,g),r.use(ge),r.use(me,{preWrapper:h}),h&&(r.use(C,{lineNumbers:a,resolveLineNumbers(d){return s.twoslash&&Y.test(d)?!1:void 0}}),r.use(H,{collapsedLines:l}),r.use(W,{codeBlockTitle:u}))},clientConfigFile:()=>de(e,s)}};export{fe as shikiPlugin};
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/node/markdown/highlighter/createMarkdownFilePathGetter.ts","../../src/node/transformers/vuepressTransformers.ts","../../src/node/utils.ts","../../src/node/markdown/highlighter/createShikiHighlighter.ts","../../src/node/transformers/getTransformers.ts","../../src/node/markdown/highlighter/getLanguage.ts","../../src/node/markdown/highlighter/handleMustache.ts","../../src/node/markdown/highlighter/getHighLightFunction.ts","../../src/node/markdown/preWrapperPlugin.ts","../../src/node/markdown/highlightLinesPlugin.ts","../../src/node/prepareClientConfigFile.ts","../../src/node/shikiPlugin.ts"],"sourcesContent":["import type MarkdownIt from 'markdown-it'\nimport type { MarkdownEnv } from 'vuepress/markdown'\n\n/**\n * Markdown file path getter function type\n *\n * Markdown 文件路径获取器函数类型\n */\nexport type MarkdownFilePathGetter = () => string\n\n/**\n * Create a function to get current markdown file path\n *\n * 创建获取当前 markdown 文件路径的函数\n *\n * @param md - MarkdownIt instance / MarkdownIt 实例\n *\n * @returns Function to get current markdown file path / 获取当前 markdown 文件路径的函数\n */\nexport const createMarkdownFilePathGetter = (\n md: MarkdownIt,\n): MarkdownFilePathGetter => {\n const store: { path?: string | null } = {}\n\n const rawRender = md.render.bind(md)\n\n // we need to store file path before each render\n md.render = (src, env: MarkdownEnv = {}): string => {\n store.path = env.filePathRelative\n\n return rawRender(src, env)\n }\n\n return () => store.path || 'dynamic pages'\n}\n","import type { ShikiTransformer } from 'shiki'\n\nconst CODE_ESCAPE_RE = /\\[\\\\!code/g\n\n/**\n * A transformer to add `vp-code` class to code blocks for better styling\n */\nexport const addClassTransformer: ShikiTransformer = {\n name: 'vuepress:add-class',\n pre(node) {\n this.addClassToHast(node, 'vp-code')\n },\n}\n\n/**\n * A transformer to remove `tabindex` property from code blocks to avoid being focused\n */\nexport const cleanupTransformer: ShikiTransformer = {\n name: 'vuepress:cleanup',\n pre(node) {\n delete node.properties.tabindex\n },\n}\n\n/**\n * This `transformer` is primarily for the usage instructions of themes.\n * When developers need to provide an example like `// [!code xxx]`,\n * they can use `// [\\!code xxx]` to avoid being processed by `shiki`.\n * After `shiki` completes the processing,\n * replace `[\\!code` back with `[!code` to display the correct text.\n */\nexport const removeEscapeTransformer: ShikiTransformer = {\n name: 'vuepress:remove-escape',\n postprocess: (code) => code.replace(CODE_ESCAPE_RE, '[!code'),\n}\n\n/**\n * This transformer adds a `wbr` tag to the end of the empty line to insure the empty line can be correctly displayed\n */\nexport const emptyLineTransformer: ShikiTransformer = {\n name: 'vuepress:empty-line',\n code(hast) {\n hast.children.forEach((span) => {\n if (\n span.type === 'element' &&\n span.tagName === 'span' &&\n Array.isArray(span.properties.class) &&\n span.properties.class.includes('line') &&\n span.children.length === 0\n ) {\n span.children.push({\n type: 'element',\n tagName: 'wbr',\n properties: {},\n children: [],\n })\n }\n })\n },\n}\n\n/**\n * A transformer to add `v-pre` directive to code blocks to avoid being processed by Vue\n */\nexport const vPreTransformer: ShikiTransformer = {\n name: 'vuepress:v-pre',\n pre(node) {\n node.properties['v-pre'] = ''\n },\n}\n","import type { TransformerCompactLineOption } from '@shikijs/transformers'\nimport { Logger } from '@vuepress/helper'\nimport { customAlphabet } from 'nanoid'\n\nconst VUE_RE = /-vue$/\n\nexport const TWOSLASH_RE = /\\btwoslash\\b/\n\nexport const PLUGIN_NAME = '@vuepress/plugin-shiki'\n\nexport const logger = new Logger(PLUGIN_NAME)\n\nexport const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)\n\n/**\n * Resolve language from code fence info string\n *\n * 从代码围栏信息字符串中解析语言\n *\n * @param info - Code fence info string / 代码围栏信息字符串\n *\n * @returns Resolved language / 解析的语言\n */\nexport const resolveLanguage = (info: string): string =>\n info\n .match(/^([^ :[{]+)/)?.[1]\n ?.replace(VUE_RE, '')\n .toLowerCase() ?? ''\n\n/**\n * Convert attributes to line options\n *\n * 将属性转换为行选项\n *\n * @description 2 steps:\n * 1. convert attrs into line numbers:\n * {4,7-13,16,23-27,40} -> [4,7,8,9,10,11,12,13,16,23,24,25,26,27,40]\n * 2. convert line numbers into line options:\n * [{ line: number, classes: string[] }]\n *\n * 转换分为两步:\n * 1. 将属性转换为行号数组\n * 2. 将行号数组转换为行选项\n *\n * @param attrs - Attributes string / 属性字符串\n *\n * @returns Line options array / 行选项数组\n */\nexport const attrsToLines = (attrs: string): TransformerCompactLineOption[] => {\n const attrsContent = attrs.match(/\\s*[\\d,-]*?$/)?.[0].trim()\n const result: number[] = []\n\n if (!attrsContent) {\n return []\n }\n\n attrsContent\n .split(',')\n .map((lineNumberConfig) =>\n lineNumberConfig\n .split('-')\n .map((lineNumber) => Number.parseInt(lineNumber, 10)),\n )\n .forEach(([start, end]) => {\n if (start && end) {\n result.push(\n ...Array.from({ length: end - start + 1 }, (_, i) => start + i),\n )\n } else {\n result.push(start)\n }\n })\n\n return result.map((line) => ({\n line,\n classes: ['highlighted'],\n }))\n}\n","import { createRequire } from 'node:module'\nimport type {\n BundledLanguage,\n BundledTheme,\n HighlighterGeneric,\n ShikiTransformer,\n Grammar,\n} from 'shiki'\nimport { createHighlighter, isSpecialLang } from 'shiki'\nimport { createSyncFn } from 'synckit'\nimport type { App } from 'vuepress'\nimport { isPlainObject } from 'vuepress/shared'\nimport type { ShikiPluginOptions } from '../../options.js'\nimport type { ShikiResolveLang } from '../../resolveLang.js'\nimport { vPreTransformer } from '../../transformers/vuepressTransformers.js'\nimport { resolveLanguage } from '../../utils.js'\n\nconst require = createRequire(import.meta.url)\n\nconst resolveLangSync = createSyncFn<ShikiResolveLang>(\n require.resolve('@vuepress/plugin-shiki/resolveLang'),\n)\n\n/**\n * Load language function type\n *\n * 加载语言函数类型\n */\nexport type ShikiLoadLang = (lang: string) => boolean\n\n/**\n * Create Shiki highlighter with additional features\n *\n * 创建带有额外功能的 Shiki 高亮器\n *\n * @param app - VuePress app instance / VuePress 应用实例\n * @param options - Plugin options / 插件选项\n * @param enableVPre - Whether to enable v-pre transformer / 是否启用 v-pre 转换器\n *\n * @default enableVPre: true\n *\n * @returns Object containing highlighter, loadLang function and extra transformers / 包含高亮器、loadLang 函数和额外转换器的对象\n */\nexport const createShikiHighlighter = async (\n app: App,\n {\n langs = [],\n langAlias = {},\n defaultLang: _,\n shikiSetup,\n ...options\n }: ShikiPluginOptions = {},\n enableVPre = true,\n): Promise<{\n highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>\n loadLang: ShikiLoadLang\n extraTransformers: ShikiTransformer[]\n}> => {\n const highlighter = await createHighlighter({\n langs: [...langs, ...Object.values(langAlias)],\n langAlias,\n themes:\n 'themes' in options\n ? Object.values(options.themes)\n : [options.theme ?? 'nord'],\n })\n\n const loadLang = (lang: string): boolean => {\n if (isSpecialLang(lang)) return true\n\n const loadedLangs = highlighter.getLoadedLanguages()\n\n if (!loadedLangs.includes(lang)) {\n const resolvedLang = resolveLangSync(lang)\n\n if (resolvedLang.length === 0) return false\n\n highlighter.loadLanguageSync(resolvedLang)\n }\n\n return true\n }\n\n // patch for twoslash - https://github.com/vuejs/vitepress/issues/4334\n const rawGetLanguage = highlighter.getLanguage\n\n highlighter.getLanguage = (name): Grammar => {\n const lang = typeof name === 'string' ? name : name.name\n\n loadLang(resolveLanguage(lang))\n\n return rawGetLanguage.call(highlighter, name)\n }\n\n const extraTransformers: ShikiTransformer[] = []\n\n if (enableVPre) extraTransformers.push(vPreTransformer)\n\n if (options.twoslash) {\n const { createTwoslashTransformer, createFileSystemTypesCache } =\n await import('@vuepress/shiki-twoslash')\n\n const { typesCache, ...twoslashOptions } = isPlainObject(options.twoslash)\n ? options.twoslash\n : {}\n extraTransformers.push(\n await createTwoslashTransformer({\n ...twoslashOptions,\n typesCache:\n typesCache === true || typeof typesCache === 'undefined'\n ? createFileSystemTypesCache({\n dir: app.dir.cache('markdown/twoslash'),\n })\n : typesCache,\n }),\n )\n }\n\n await shikiSetup?.(highlighter)\n\n return { highlighter, loadLang, extraTransformers }\n}\n","import {\n transformerMetaWordHighlight,\n transformerNotationDiff,\n transformerNotationErrorLevel,\n transformerNotationFocus,\n transformerNotationHighlight,\n transformerNotationWordHighlight,\n transformerRenderWhitespace,\n} from '@shikijs/transformers'\nimport type { WhitespacePosition } from '@vuepress/highlighter-helper'\nimport { resolveWhitespacePosition } from '@vuepress/highlighter-helper'\nimport type { ShikiTransformer } from 'shiki'\nimport type { ShikiHighlightOptions } from '../types.js'\nimport {\n addClassTransformer,\n cleanupTransformer,\n emptyLineTransformer,\n removeEscapeTransformer,\n} from './vuepressTransformers.js'\n\nexport const getTransformers = (\n options: ShikiHighlightOptions & {\n twoslash?: boolean\n },\n): ShikiTransformer[] => {\n const transformers: ShikiTransformer[] = []\n\n if (options.notationDiff) {\n transformers.push(transformerNotationDiff())\n }\n\n if (options.notationFocus) {\n transformers.push(\n transformerNotationFocus({\n classActiveLine: 'has-focus',\n classActivePre: 'has-focused-lines',\n }),\n )\n }\n\n if (options.notationHighlight) {\n transformers.push(transformerNotationHighlight())\n }\n\n if (options.notationErrorLevel) {\n transformers.push(transformerNotationErrorLevel())\n }\n\n if (options.notationWordHighlight) {\n transformers.push(transformerNotationWordHighlight())\n transformers.push(transformerMetaWordHighlight())\n }\n\n transformers.push(\n addClassTransformer,\n cleanupTransformer,\n removeEscapeTransformer,\n emptyLineTransformer,\n )\n\n return transformers\n}\n\nexport const whitespaceTransformer = (\n meta: string,\n globalOption: WhitespacePosition | true = true,\n): ShikiTransformer[] => {\n const position = resolveWhitespacePosition(meta, globalOption)\n\n return position ? [transformerRenderWhitespace({ position })] : []\n}\n","import { colors } from 'vuepress/utils'\nimport type { ShikiHighlightOptions } from '../../types.js'\nimport { logger, resolveLanguage } from '../../utils.js'\nimport type { MarkdownFilePathGetter } from './createMarkdownFilePathGetter.js'\nimport type { ShikiLoadLang } from './createShikiHighlighter.js'\n\nconst WARNED_LANGS = new Set<string>()\n\nexport const getLanguage = (\n lang: string,\n { defaultLang, logLevel }: ShikiHighlightOptions,\n loadLang: ShikiLoadLang,\n markdownFilePathGetter: MarkdownFilePathGetter,\n): string => {\n let result = resolveLanguage(lang)\n\n if (result && !loadLang(result)) {\n // warn for unknown languages only once\n if (logLevel !== 'silent' && !WARNED_LANGS.has(result)) {\n logger.warn(\n `Missing ${colors.cyan(lang)} highlighter, ${defaultLang ? `use ${colors.cyan(defaultLang)} to highlight instead.` : 'skip highlighting'}`,\n )\n WARNED_LANGS.add(result)\n }\n\n // log file path if unknown language is found\n if (logLevel === 'debug') {\n logger.info(\n `Unknown language ${colors.cyan(result)} found in ${colors.cyan(markdownFilePathGetter())}`,\n )\n }\n\n result = defaultLang || 'plain'\n }\n\n return result\n}\n","import { nanoid } from '../../utils.js'\n\nconst MUSTACHE_REG = /\\{\\{[^]*?\\}\\}/g\n\ntype MustacheStore = Map<string, string>\n\n/**\n * Replace mustache with unique markers\n *\n * @param content original code content\n * @param store mustache store\n * @returns content with mustache replaced by unique markers\n */\nconst removeMustache = (content: string, store: MustacheStore): string =>\n content.replace(MUSTACHE_REG, (match) => {\n let marker = store.get(match)\n\n if (!marker) {\n marker = nanoid()\n store.set(match, marker)\n }\n\n return marker\n })\n\n/**\n * Replace mustache back from unique markers\n *\n * @param content content with unique markers\n * @param store mustache store\n * @returns content with unique markers replaced by original mustache\n */\nconst restoreMustache = (content: string, store: MustacheStore): string => {\n let result = content\n\n store.forEach((marker, match) => {\n result = result.replaceAll(marker, match)\n })\n\n return result\n}\n\n/**\n * Handle mustache in code blocks\n *\n * @description\n * Mustache in code blocks will be replaced with unique markers before highlighting, and restored after highlighting.\n * This is to prevent mustache from being highlighted as code, which may cause issues in some cases.\n *\n * @param content content of code block\n * @param highlight function to highlight content\n * @returns highlighted content with mustache handled\n */\nexport const handleMustache = (\n content: string,\n highlight: (str: string) => string,\n): string => {\n const store = new Map<string, string>()\n\n return restoreMustache(\n highlight(removeMustache(content, store).trimEnd()),\n store,\n )\n}\n","import { transformerCompactLineOptions } from '@shikijs/transformers'\nimport type {\n BundledLanguage,\n BundledTheme,\n HighlighterGeneric,\n ShikiTransformer,\n} from 'shiki'\nimport {\n getTransformers,\n whitespaceTransformer,\n} from '../../transformers/getTransformers.js'\nimport type { ShikiHighlightOptions } from '../../types.js'\nimport { attrsToLines } from '../../utils.js'\nimport type { MarkdownFilePathGetter } from './createMarkdownFilePathGetter.js'\nimport type { ShikiLoadLang } from './createShikiHighlighter.js'\nimport { getLanguage } from './getLanguage.js'\nimport { handleMustache } from './handleMustache.js'\n\ntype MarkdownItHighlight = (\n content: string,\n language: string,\n attrs: string,\n) => string\n\n/**\n * Get highlight function for markdown-it\n *\n * 获取 markdown-it 的高亮函数\n *\n * @param highlighter - Shiki highlighter instance / Shiki 高亮器实例\n * @param options - Highlight options / 高亮选项\n * @param extraTransformers - Extra transformers / 额外转换器\n * @param loadLang - Language loader function / 语言加载函数\n * @param markdownFilePathGetter - Markdown file path getter / Markdown 文件路径获取器\n *\n * @returns Highlight function for markdown-it / markdown-it 的高亮函数\n */\nexport const getHighLightFunction = (\n highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>,\n options: ShikiHighlightOptions,\n extraTransformers: ShikiTransformer[] | undefined,\n loadLang: ShikiLoadLang,\n markdownFilePathGetter: MarkdownFilePathGetter,\n): MarkdownItHighlight => {\n const transformers = getTransformers(options)\n\n return (content, language, attrs) =>\n handleMustache(content, (str) =>\n highlighter.codeToHtml(str, {\n lang: getLanguage(language, options, loadLang, markdownFilePathGetter),\n meta: {\n /**\n * Custom `transformers` passed by users may require `attrs`.\n * e.g. [transformerNotationWordHighlight](https://shiki.style/packages/transformers#transformernotationwordhighlight)\n */\n __raw: attrs,\n },\n transformers: [\n ...transformers,\n ...((options.highlightLines ?? true)\n ? [transformerCompactLineOptions(attrsToLines(attrs))]\n : []),\n ...(options.whitespace\n ? whitespaceTransformer(attrs, options.whitespace)\n : []),\n ...(extraTransformers ?? []),\n ...(options.transformers ?? []),\n ],\n ...('themes' in options\n ? {\n themes: options.themes,\n defaultColor: false,\n }\n : { theme: options.theme ?? 'nord' }),\n }),\n )\n}\n","// markdown-it plugin for generating line numbers.\n// v-pre block logic is in `../highlight.ts`\nimport type { Markdown } from 'vuepress/markdown'\nimport { resolveLanguage } from '../utils.js'\n\nconst PRE_ATTRS_REGEXP = /<pre([\\s\\S]*?)style=\"([^\"]*)\"([^>]*)>/\n\nexport interface MarkdownItPreWrapperOptions {\n /**\n * Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you\n * understand what's it for\n *\n * - Required for line numbers, title display and code block collapsing\n */\n preWrapper?: boolean\n}\n\n/**\n * A markdown-it plugin for wrapping `<pre>` tag with an extra `<div>`\n *\n * 一个用于为 `<pre>` 标签添加额外 `<div>` 包装的 markdown-it 插件\n *\n * @param md - MarkdownIt instance / MarkdownIt 实例\n * @param options - Plugin options / 插件选项\n *\n * @default { preWrapper: true }\n */\nexport const preWrapperPlugin = (\n md: Markdown,\n { preWrapper = true }: MarkdownItPreWrapperOptions = {},\n): void => {\n const rawFence = md.renderer.rules.fence!\n\n md.renderer.rules.fence = (...args): string => {\n let result = rawFence(...args)\n\n if (!result.startsWith('<pre')) {\n return result\n }\n\n const [tokens, idx, options] = args\n const token = tokens[idx]\n\n // get token info\n const info = token.info ? md.utils.unescapeAll(token.info).trim() : ''\n\n const lang = resolveLanguage(info)\n const languageClass = `${options.langPrefix}${lang}`\n\n result = result.replace(/<code[^]*?>/, `<code class=\"${languageClass}\">`)\n if (!preWrapper) {\n result = `<pre class=\"${languageClass} ${result.slice('<pre class=\"'.length)}`\n return result\n }\n let styles = ''\n\n // before: maybe `v-pre class=\"shiki *\"`\n // after: style=\"*\" tab-index=\"*\"\n result = result.replace(\n PRE_ATTRS_REGEXP,\n (_, before: string, style: string, after: string) => {\n styles = style.trim()\n // Keep `v-pre class=\"*\"`, remove the rest.\n return `<pre ${before.trim()}${after.trimEnd()}>`\n },\n )\n\n /**\n * Add information to dataset for current code block.\n */\n return `<div class=\"${languageClass}\" data-highlighter=\"shiki\" data-ext=\"${lang}\" style=\"${styles}\">${result}</div>`\n }\n}\n","// Modified from https://github.com/egoist/markdown-it-highlight-lines\n// Now this plugin is only used to normalize line attrs.\n// The else part of line highlights logic is in './highlight.ts'.\n\nimport type { Markdown } from 'vuepress/markdown'\n\nconst HIGHLIGHT_LINES_REGEXP = /{([\\d,-]+?)}/\n\nexport const highlightLinePlugin = (md: Markdown): void => {\n const fence = md.renderer.rules.fence!\n\n md.renderer.rules.fence = (...args): string => {\n const [tokens, idx] = args\n const token = tokens[idx]\n\n // due to use of markdown-it-attrs, the {0} syntax would have been\n // converted to attrs on the token\n const attr = token.attrs?.[0]\n\n let lines: string | null = null\n\n if (!attr) {\n // markdown-it-attrs maybe disabled\n const rawInfo = token.info\n\n if (!rawInfo || !HIGHLIGHT_LINES_REGEXP.test(rawInfo)) {\n return fence(...args)\n }\n\n const langName = rawInfo.replace(HIGHLIGHT_LINES_REGEXP, '').trim()\n\n // ensure the next plugin get the correct lang\n token.info = langName\n\n ;[, lines] = HIGHLIGHT_LINES_REGEXP.exec(rawInfo)!\n }\n\n if (!lines) {\n ;[lines] = attr!\n\n if (!lines || !/[\\d,-]+/.test(lines)) {\n return fence(...args)\n }\n }\n\n token.info += ` ${lines}`\n return fence(...args)\n }\n}\n","import { getModulePath } from '@vuepress/helper'\nimport type { App } from 'vuepress'\nimport type { ShikiPluginOptions } from './options.js'\nimport { PLUGIN_NAME } from './utils.js'\n\n// oxlint-disable-next-line max-lines-per-function, complexity, max-statements\nexport const prepareClientConfigFile = (\n app: App,\n {\n lineNumbers = true,\n highlightLines = true,\n collapsedLines = 'disable',\n codeBlockTitle = true,\n notationDiff,\n notationErrorLevel,\n notationFocus,\n notationHighlight,\n notationWordHighlight,\n whitespace,\n twoslash,\n }: ShikiPluginOptions,\n): Promise<string> => {\n const imports: string[] = [\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/base.css', import.meta)}\"`,\n `import \"${getModulePath(`${PLUGIN_NAME}/styles/shiki.css`, import.meta)}\"`,\n ]\n\n const enhances: string[] = []\n const setups: string[] = []\n\n if (lineNumbers !== 'disable') {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/line-numbers.css', import.meta)}\"`,\n )\n }\n\n if (highlightLines || notationHighlight) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-highlight.css', import.meta)}\"`,\n )\n }\n\n if (notationDiff) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-diff.css', import.meta)}\"`,\n )\n }\n\n if (notationErrorLevel) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-error-level.css', import.meta)}\"`,\n )\n }\n\n if (notationFocus) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-focus.css', import.meta)}\"`,\n )\n }\n\n if (notationHighlight) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-highlight.css', import.meta)}\"`,\n )\n }\n\n if (notationWordHighlight) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/notation-word-highlight.css', import.meta)}\"`,\n )\n }\n\n if (whitespace) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/whitespace.css', import.meta)}\"`,\n )\n }\n\n if (collapsedLines !== 'disable') {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/collapsed-lines.css', import.meta)}\"`,\n `import { setupCollapsedLines } from \"${getModulePath('@vuepress/highlighter-helper/client', import.meta)}\"`,\n )\n setups.push('setupCollapsedLines()')\n }\n\n if (codeBlockTitle) {\n imports.push(\n `import \"${getModulePath('@vuepress/highlighter-helper/styles/code-block-title.css', import.meta)}\"`,\n )\n }\n\n if (twoslash) {\n imports.push(\n `import { enhanceTwoslash } from \"${getModulePath('@vuepress/shiki-twoslash/client', import.meta)}\"`,\n )\n imports.push(\n `import \"${getModulePath('@vuepress/shiki-twoslash/styles/twoslash.css', import.meta)}\"`,\n )\n enhances.push('enhanceTwoslash(app)')\n }\n\n let code = imports.join('\\n')\n\n if (setups.length || enhances.length) {\n code += `\nexport default {\n`\n\n if (enhances.length) {\n code += `\\\n enhance({ app }) {\n ${enhances.join('\\n ')}\n },\n`\n }\n\n if (setups.length) {\n code += `\\\n setup() {\n ${setups.join('\\n ')}\n },\n`\n }\n\n code += `\\\n}\n`\n }\n\n return app.writeTemp('shiki/config.js', code)\n}\n","import { isModuleAvailable } from '@vuepress/helper'\nimport type {\n MarkdownItCodeBlockTitleOptions,\n MarkdownItCollapsedLinesOptions,\n MarkdownItLineNumbersOptions,\n} from '@vuepress/highlighter-helper'\nimport {\n codeBlockTitle as codeBlockTitlePlugin,\n collapsedLines as collapsedLinesPlugin,\n lineNumbers as lineNumbersPlugin,\n} from '@vuepress/highlighter-helper'\nimport type { Plugin } from 'vuepress/core'\nimport { isPlainObject } from 'vuepress/shared'\nimport { colors } from 'vuepress/utils'\nimport { createMarkdownFilePathGetter } from './markdown/highlighter/createMarkdownFilePathGetter.js'\nimport type { MarkdownItPreWrapperOptions } from './markdown/index.js'\nimport {\n createShikiHighlighter,\n getHighLightFunction,\n highlightLinePlugin,\n preWrapperPlugin,\n} from './markdown/index.js'\nimport type { ShikiPluginOptions } from './options.js'\nimport { prepareClientConfigFile } from './prepareClientConfigFile.js'\nimport { TWOSLASH_RE, logger } from './utils.js'\n\n/**\n * Shiki plugin for VuePress\n *\n * VuePress 的 Shiki 插件\n *\n * @example\n * ```ts\n * import { shikiPlugin } from '@vuepress/plugin-shiki'\n *\n * export default {\n * plugins: [\n * shikiPlugin({\n * langs: ['ts', 'json', 'vue', 'md', 'bash', 'diff'],\n * theme: 'nord',\n * lineNumbers: true,\n * }),\n * ],\n * }\n * ```\n */\nexport const shikiPlugin =\n (options: ShikiPluginOptions = {}): Plugin =>\n (app) => {\n // TODO: Remove in stable version\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const { code } = app.options.markdown\n const shikiOptions = {\n ...(isPlainObject(code) ? code : {}),\n ...options,\n }\n\n shikiOptions.logLevel ??= app.env.isDebug ? 'debug' : 'warn'\n shikiOptions.preWrapper ??= true\n shikiOptions.lineNumbers ??= true\n shikiOptions.collapsedLines ??= 'disable'\n shikiOptions.codeBlockTitle ??= true\n\n if (\n shikiOptions.twoslash &&\n !isModuleAvailable('@vuepress/shiki-twoslash', import.meta)\n ) {\n logger.error(\n `${colors.cyan('twoslash')} is enabled, but ${colors.magenta('@vuepress/shiki-twoslash')} is not installed, please install it manually`,\n )\n shikiOptions.twoslash = false\n }\n\n /**\n * Whether to enable the `v-pre` configuration of the code block\n */\n let enableVPre = true\n\n return {\n name: '@vuepress/plugin-shiki',\n\n extendsMarkdownOptions: (opts) => {\n /**\n * Turn off the `v-pre` configuration of the code block.\n */\n if (opts.vPre === false) {\n enableVPre = false\n } else {\n const vPre = isPlainObject(opts.vPre) ? opts.vPre : { block: true }\n if (vPre.block) {\n opts.vPre ??= {}\n opts.vPre.block = false\n }\n enableVPre = vPre.block ?? true\n }\n },\n\n extendsMarkdown: async (md) => {\n const { preWrapper, lineNumbers, collapsedLines, codeBlockTitle } =\n shikiOptions\n\n const markdownFilePathGetter = createMarkdownFilePathGetter(md)\n const { highlighter, loadLang, extraTransformers } =\n await createShikiHighlighter(app, shikiOptions, enableVPre)\n\n md.options.highlight = getHighLightFunction(\n highlighter,\n shikiOptions,\n extraTransformers,\n loadLang,\n markdownFilePathGetter,\n )\n md.use(highlightLinePlugin)\n md.use<MarkdownItPreWrapperOptions>(preWrapperPlugin, { preWrapper })\n if (preWrapper) {\n md.use<MarkdownItLineNumbersOptions>(lineNumbersPlugin, {\n lineNumbers,\n resolveLineNumbers(info) {\n return shikiOptions.twoslash && TWOSLASH_RE.test(info)\n ? false\n : undefined\n },\n })\n md.use<MarkdownItCollapsedLinesOptions>(collapsedLinesPlugin, {\n collapsedLines,\n })\n md.use<MarkdownItCodeBlockTitleOptions>(codeBlockTitlePlugin, {\n codeBlockTitle,\n })\n }\n },\n\n clientConfigFile: () => prepareClientConfigFile(app, shikiOptions),\n }\n }\n"],"names":["createMarkdownFilePathGetter","md","store","rawRender","src","env","CODE_ESCAPE_RE","addClassTransformer","node","cleanupTransformer","removeEscapeTransformer","code","emptyLineTransformer","hast","span","vPreTransformer","VUE_RE","TWOSLASH_RE","PLUGIN_NAME","logger","Logger","nanoid","customAlphabet","resolveLanguage","info","attrsToLines","attrs","attrsContent","result","lineNumberConfig","lineNumber","start","end","_","i","line","require","createRequire","resolveLangSync","createSyncFn","createShikiHighlighter","app","langs","langAlias","shikiSetup","options","enableVPre","highlighter","createHighlighter","loadLang","lang","isSpecialLang","resolvedLang","rawGetLanguage","name","extraTransformers","createTwoslashTransformer","createFileSystemTypesCache","typesCache","twoslashOptions","isPlainObject","getTransformers","transformers","transformerNotationDiff","transformerNotationFocus","transformerNotationHighlight","transformerNotationErrorLevel","transformerNotationWordHighlight","transformerMetaWordHighlight","whitespaceTransformer","meta","globalOption","position","resolveWhitespacePosition","transformerRenderWhitespace","WARNED_LANGS","getLanguage","defaultLang","logLevel","markdownFilePathGetter","colors","MUSTACHE_REG","removeMustache","content","match","marker","restoreMustache","handleMustache","highlight","getHighLightFunction","language","str","transformerCompactLineOptions","PRE_ATTRS_REGEXP","preWrapperPlugin","preWrapper","rawFence","args","tokens","idx","token","languageClass","styles","before","style","after","HIGHLIGHT_LINES_REGEXP","highlightLinePlugin","fence","attr","lines","rawInfo","langName","prepareClientConfigFile","lineNumbers","highlightLines","collapsedLines","codeBlockTitle","notationDiff","notationErrorLevel","notationFocus","notationHighlight","notationWordHighlight","whitespace","twoslash","imports","getModulePath","enhances","setups","shikiPlugin","shikiOptions","isModuleAvailable","opts","vPre","lineNumbersPlugin","collapsedLinesPlugin","codeBlockTitlePlugin"],"mappings":"qxBAmBO,MAAMA,EACXC,GAC2B,CAC3B,MAAMC,EAAkC,CAAA,EAElCC,EAAYF,EAAG,OAAO,KAAKA,CAAE,EAGnC,OAAAA,EAAG,OAAS,CAACG,EAAKC,EAAmB,CAAA,KACnCH,EAAM,KAAOG,EAAI,iBAEVF,EAAUC,EAAKC,CAAG,GAGpB,IAAMH,EAAM,MAAQ,eAC7B,EChCMI,EAAiB,aAKVC,EAAwC,CACnD,KAAM,qBACN,IAAIC,EAAM,CACR,KAAK,eAAeA,EAAM,SAAS,CACrC,CACF,EAKaC,EAAuC,CAClD,KAAM,mBACN,IAAID,EAAM,CACR,OAAOA,EAAK,WAAW,QACzB,CACF,EASaE,EAA4C,CACvD,KAAM,yBACN,YAAcC,GAASA,EAAK,QAAQL,EAAgB,QAAQ,CAC9D,EAKaM,EAAyC,CACpD,KAAM,sBACN,KAAKC,EAAM,CACTA,EAAK,SAAS,QAASC,GAAS,CAE5BA,EAAK,OAAS,WACdA,EAAK,UAAY,QACjB,MAAM,QAAQA,EAAK,WAAW,KAAK,GACnCA,EAAK,WAAW,MA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,EAAK,OAAS,CAAA,EACdA,EAAK,KAAK,MAAQ,IAEpBtF,EAAauF,EAAK,OAAS,EAC7B,CACF,EAEA,gBAAiB,MAAOpI,GAAO,CAC7B,KAAM,CAAE,WAAA8F,EAAY,YAAAmB,EAAa,eAAAE,EAAgB,eAAAC,CAAe,EAC9Da,EAEInD,EAAyB/E,EAA6BC,CAAE,EACxD,CAAE,YAAA8C,EAAa,SAAAE,EAAU,kBAAAM,CAAkB,EAC/C,MAAMf,GAAuBC,EAAKyF,EAAcpF,CAAU,EAE5D7C,EAAG,QAAQ,UAAYwF,GACrB1C,EACAmF,EACA3E,EACAN,EACA8B,CACF,EACA9E,EAAG,IAAI0G,EAAmB,EAC1B1G,EAAG,IAAiC6F,GAAkB,CAAE,WAAAC,CAAW,CAAC,EAChEA,IACF9F,EAAG,IAAkCqI,EAAmB,CACtD,YAAApB,EACA,mBAAmB1F,EAAM,CACvB,OAAO0G,EAAa,UAAYjH,EAAY,KAAKO,CAAI,EACjD,GACA,MACN,CACF,CAAC,EACDvB,EAAG,IAAqCsI,EAAsB,CAC5D,eAAAnB,CACF,CAAC,EACDnH,EAAG,IAAqCuI,EAAsB,CAC5D,eAAAnB,CACF,CAAC,EAEL,EAEA,iBAAkB,IAAMJ,GAAwBxE,EAAKyF,CAAY,CACnE,CACF"}
@@ -1,6 +0,0 @@
1
- import { LanguageRegistration } from 'shiki';
2
-
3
- declare const resolveLang: (lang: string) => Promise<LanguageRegistration[]>;
4
- type ShikiResolveLang = typeof resolveLang;
5
-
6
- export type { ShikiResolveLang };
@@ -1,2 +0,0 @@
1
- import{bundledLanguages as o}from"shiki";import{runAsWorker as t}from"synckit";const e=async r=>o[r]?.().then(n=>n.default)??[];t(e);
2
- //# sourceMappingURL=resolveLang.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveLang.js","sources":["../../src/node/resolveLang.ts"],"sourcesContent":["// oxlint-disable no-unexpected-multiline\nimport type {\n DynamicImportLanguageRegistration,\n LanguageRegistration,\n} from 'shiki'\nimport { bundledLanguages } from 'shiki'\nimport { runAsWorker } from 'synckit'\n\nconst resolveLang = async (lang: string): Promise<LanguageRegistration[]> =>\n (\n bundledLanguages as Record<\n string,\n DynamicImportLanguageRegistration | undefined\n >\n )\n [lang]?.()\n .then((mod) => mod.default) ?? []\n\nrunAsWorker(resolveLang)\n\nexport type ShikiResolveLang = typeof resolveLang\n"],"names":["resolveLang","lang","bundledLanguages","mod","runAsWorker"],"mappings":"+EAQA,MAAMA,EAAc,MAAOC,GAEvBC,EAKCD,CAAI,IAAA,EACJ,KAAME,GAAQA,EAAI,OAAO,GAAK,CAAA,EAEnCC,EAAYJ,CAAW"}
File without changes
File without changes