@vuepress/plugin-shiki 2.0.0-rc.46 → 2.0.0-rc.52
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.
- package/lib/node/index.d.ts +152 -7
- package/lib/node/index.js +11 -7
- package/lib/node/index.js.map +1 -0
- package/package.json +7 -7
- package/lib/node/markdown/applyHighlighter/createMarkdownFilePathGetter.d.ts +0 -3
- package/lib/node/markdown/applyHighlighter/createMarkdownFilePathGetter.js +0 -10
- package/lib/node/markdown/applyHighlighter/getLanguage.d.ts +0 -2
- package/lib/node/markdown/applyHighlighter/getLanguage.js +0 -20
- package/lib/node/markdown/applyHighlighter/handleMustache.d.ts +0 -1
- package/lib/node/markdown/applyHighlighter/handleMustache.js +0 -27
- package/lib/node/markdown/applyHighlighter/index.d.ts +0 -4
- package/lib/node/markdown/applyHighlighter/index.js +0 -46
- package/lib/node/markdown/highlightLinesPlugin.d.ts +0 -2
- package/lib/node/markdown/highlightLinesPlugin.js +0 -21
- package/lib/node/markdown/index.d.ts +0 -3
- package/lib/node/markdown/index.js +0 -3
- package/lib/node/markdown/preWrapperPlugin.d.ts +0 -3
- package/lib/node/markdown/preWrapperPlugin.js +0 -48
- package/lib/node/options.d.ts +0 -17
- package/lib/node/options.js +0 -1
- package/lib/node/prepareConfigFile.d.ts +0 -3
- package/lib/node/prepareConfigFile.js +0 -48
- package/lib/node/shiki.d.ts +0 -2
- package/lib/node/shiki.js +0 -3
- package/lib/node/shikiPlugin.d.ts +0 -3
- package/lib/node/shikiPlugin.js +0 -34
- package/lib/node/transformers/getTransformers.d.ts +0 -5
- package/lib/node/transformers/getTransformers.js +0 -34
- package/lib/node/transformers/index.d.ts +0 -2
- package/lib/node/transformers/index.js +0 -2
- package/lib/node/transformers/vuepressTransformers.d.ts +0 -12
- package/lib/node/transformers/vuepressTransformers.js +0 -45
- package/lib/node/types.d.ts +0 -138
- package/lib/node/types.js +0 -1
- package/lib/node/utils.d.ts +0 -16
- package/lib/node/utils.js +0 -48
package/lib/node/index.d.ts
CHANGED
|
@@ -1,7 +1,152 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Plugin } from 'vuepress/core';
|
|
2
|
+
import { WhitespacePosition, MarkdownItLineNumbersOptions, MarkdownItCollapsedLinesOptions } from '@vuepress/highlighter-helper';
|
|
3
|
+
import { LanguageInput, SpecialLanguage, StringLiteralUnion, BundledLanguage, BundledTheme, ThemeRegistrationAny, Highlighter, ShikiTransformer } from 'shiki';
|
|
4
|
+
export { bundledLanguages } from 'shiki';
|
|
5
|
+
|
|
6
|
+
type ShikiLang = LanguageInput | SpecialLanguage | StringLiteralUnion<BundledLanguage>;
|
|
7
|
+
type ShikiTheme = StringLiteralUnion<BundledTheme> | ThemeRegistrationAny;
|
|
8
|
+
interface ShikiSingleThemeOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The single theme to use
|
|
11
|
+
*
|
|
12
|
+
* @see https://shiki.style/themes
|
|
13
|
+
*
|
|
14
|
+
* @default 'nord'
|
|
15
|
+
*/
|
|
16
|
+
theme?: ShikiTheme;
|
|
17
|
+
}
|
|
18
|
+
interface ShikiDualThemeOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The dark and light themes to use
|
|
21
|
+
*
|
|
22
|
+
* @see https://shiki.style/themes
|
|
23
|
+
*/
|
|
24
|
+
themes: {
|
|
25
|
+
dark: ShikiTheme;
|
|
26
|
+
light: ShikiTheme;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
type ShikiThemeOptions = ShikiDualThemeOptions | ShikiSingleThemeOptions;
|
|
30
|
+
type ShikiHighlightOptions = ShikiThemeOptions & {
|
|
31
|
+
/**
|
|
32
|
+
* Languages to be loaded.
|
|
33
|
+
*
|
|
34
|
+
* Shiki does not preload any languages to avoid extra overhead. So you need
|
|
35
|
+
* to specify the languages you want to use.
|
|
36
|
+
*
|
|
37
|
+
* @see https://shiki.style/languages
|
|
38
|
+
*/
|
|
39
|
+
langs?: ShikiLang[];
|
|
40
|
+
/**
|
|
41
|
+
* Language alias
|
|
42
|
+
*
|
|
43
|
+
* @see https://shiki.style/guide/load-lang#custom-language-aliases
|
|
44
|
+
*/
|
|
45
|
+
langAlias?: Record<string, StringLiteralUnion<BundledLanguage>>;
|
|
46
|
+
/**
|
|
47
|
+
* Fallback language when the specified language is not available.
|
|
48
|
+
*
|
|
49
|
+
* @default 'plain'
|
|
50
|
+
*/
|
|
51
|
+
defaultLang?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Function to customize Shiki highlighter instance.
|
|
54
|
+
*/
|
|
55
|
+
shikiSetup?: (shiki: Highlighter) => Promise<void> | void;
|
|
56
|
+
/**
|
|
57
|
+
* Shiki transformers
|
|
58
|
+
*/
|
|
59
|
+
transformers?: ShikiTransformer[];
|
|
60
|
+
/**
|
|
61
|
+
* Enable highlight lines or not
|
|
62
|
+
*
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
highlightLines?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Enable notation diff transformer
|
|
68
|
+
*
|
|
69
|
+
* @default false
|
|
70
|
+
*
|
|
71
|
+
* @see https://shiki.style/packages/transformers#transformernotationdiff
|
|
72
|
+
*/
|
|
73
|
+
notationDiff?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Enable notation focus transformer
|
|
76
|
+
*
|
|
77
|
+
* @default false
|
|
78
|
+
*
|
|
79
|
+
* @see https://shiki.style/packages/transformers#transformernotationfocus
|
|
80
|
+
*/
|
|
81
|
+
notationFocus?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Enable notation highlight transformer
|
|
84
|
+
*
|
|
85
|
+
* @default false
|
|
86
|
+
*
|
|
87
|
+
* @see https://shiki.style/packages/transformers#transformernotationhighlight
|
|
88
|
+
*/
|
|
89
|
+
notationHighlight?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Enable notation error level transformer
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
*
|
|
95
|
+
* @see https://shiki.style/packages/transformers#transformernotationerrorlevel
|
|
96
|
+
*/
|
|
97
|
+
notationErrorLevel?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Enable notation word highlight transformer
|
|
100
|
+
*
|
|
101
|
+
* @default false
|
|
102
|
+
*
|
|
103
|
+
* @see https://shiki.style/packages/transformers#transformernotationwordhighlight
|
|
104
|
+
*/
|
|
105
|
+
notationWordHighlight?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Enable whitespace
|
|
108
|
+
* - true: enable render whitespace, same of `all`
|
|
109
|
+
* - false: disable render whitespace
|
|
110
|
+
* - 'all': render all whitespace
|
|
111
|
+
* - 'boundary': render leading and trailing whitespace of each line.
|
|
112
|
+
* - 'trailing': render trailing whitespace of each line
|
|
113
|
+
*
|
|
114
|
+
* you are able to use `:whitespace` or `:no-whitespace` or `:whitespace=position` to set single code block
|
|
115
|
+
*
|
|
116
|
+
* position: 'all' | 'boundary' | 'trailing'
|
|
117
|
+
*
|
|
118
|
+
* @default false
|
|
119
|
+
*
|
|
120
|
+
* @see https://shiki.style/packages/transformers#transformerrenderwhitespace
|
|
121
|
+
*/
|
|
122
|
+
whitespace?: WhitespacePosition | boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Log level Highlighter language detecter
|
|
125
|
+
*
|
|
126
|
+
* @description defaults to `'debug'` when `--debug` flag is enabled
|
|
127
|
+
*
|
|
128
|
+
* @default 'warn'
|
|
129
|
+
*/
|
|
130
|
+
logLevel?: 'debug' | 'silent' | 'warn';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
interface MarkdownItPreWrapperOptions {
|
|
134
|
+
/**
|
|
135
|
+
* Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
|
|
136
|
+
* understand what's it for
|
|
137
|
+
*
|
|
138
|
+
* - Required for line numbers, title display and code block collapsing
|
|
139
|
+
*/
|
|
140
|
+
preWrapper?: boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Options of @vuepress/plugin-shiki
|
|
145
|
+
*/
|
|
146
|
+
type ShikiPluginOptions = MarkdownItLineNumbersOptions & MarkdownItPreWrapperOptions & Pick<MarkdownItCollapsedLinesOptions, 'collapsedLines'> & ShikiHighlightOptions;
|
|
147
|
+
|
|
148
|
+
declare const shikiPlugin: (options?: ShikiPluginOptions) => Plugin;
|
|
149
|
+
|
|
150
|
+
declare const bundledLanguageNames: string[];
|
|
151
|
+
|
|
152
|
+
export { type ShikiDualThemeOptions, type ShikiHighlightOptions, type ShikiLang, type ShikiPluginOptions, type ShikiSingleThemeOptions, type ShikiTheme, type ShikiThemeOptions, bundledLanguageNames, shikiPlugin as default, shikiPlugin };
|
package/lib/node/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import{resolveWhitespacePosition as H,lineNumbers as P,collapsedLines as T}from"@vuepress/highlighter-helper";import{isPlainObject as x}from"vuepress/shared";import{Logger as C,getRealPath as p}from"@vuepress/helper";import{customAlphabet as j}from"nanoid";import{transformerNotationDiff as M,transformerNotationFocus as F,transformerNotationHighlight as D,transformerNotationErrorLevel as O,transformerNotationWordHighlight as R,transformerMetaWordHighlight as S,transformerRenderWhitespace as q,transformerCompactLineOptions as _}from"@shikijs/transformers";import{bundledLanguages as G,isSpecialLang as I,createHighlighter as U}from"shiki";import{bundledLanguages as we}from"shiki";import{colors as v}from"vuepress/utils";const L=Object.keys(G),z=/\[\\!code/g,B={name:"vuepress:add-class",pre(e){this.addClassToHast(e,"vp-code")}},J={name:"vuepress:cleanup",pre(e){delete e.properties.tabindex}},K={name:"vuepress:remove-escape",postprocess(e){return e.replace(z,"[!code")}},Q={name:"vuepress:empty-line",code(e){e.children.forEach(s=>{s.type==="element"&&s.tagName==="span"&&Array.isArray(s.properties.class)&&s.properties.class.includes("line")&&s.children.length===0&&s.children.push({type:"element",tagName:"wbr",properties:{},children:[]})})}},V=e=>{const s=[];return e.notationDiff&&s.push(M()),e.notationFocus&&s.push(F({classActiveLine:"has-focus",classActivePre:"has-focused-lines"})),e.notationHighlight&&s.push(D()),e.notationErrorLevel&&s.push(O()),e.notationWordHighlight&&(s.push(R()),s.push(S())),s.push(B,J,K,Q),s},X=(e,s=!1)=>{const t=H(e,s);return t===!1?[]:[q({position:t})]},Y=/-vue$/,y="@vuepress/plugin-shiki",b=new C(y),Z=j("abcdefghijklmnopqrstuvwxyz",10),w=e=>e.match(/^([^ :[{]+)/)?.[1]?.replace(Y,"").toLowerCase()??"",ee=(e,s)=>{const t=`\\b${s}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`,r=new RegExp(t,"i");return e.match(r)?.groups?.content??null},se=e=>{const s=e.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/,"$1").trim(),t=[];return s?(s.split(",").map(r=>r.split("-").map(n=>parseInt(n,10))).forEach(([r,n])=>{r&&n?t.push(...Array.from({length:n-r+1},(i,o)=>r+o)):t.push(r)}),t.map(r=>({line:r,classes:["highlighted"]}))):[]},te=e=>{const s={},t=e.render.bind(e);return e.render=(r,n)=>(s.path=n.filePathRelative,t(r,n)),()=>s.path||"dynamic pages"},k=new Set,re=(e,s,t,r,n)=>{let i=w(e);return i&&!s.includes(i)&&!I(i)&&(r!=="silent"&&!k.has(i)&&(b.warn(`Missing ${v.cyan(e)} highlighter, ${t?`use ${v.cyan(t)} to highlight instead.`:"skip highlighting"}`),k.add(i)),r==="debug"&&b.info(`Unknown language ${v.cyan(i)} found in ${v.cyan(n())}`),i=t||"plain"),i},ne=/\{\{[^]*?\}\}/g,ie=(e,s)=>e.replace(ne,t=>{let r=s.get(t);return r||(r=Z(),s.set(t,r)),r}),oe=(e,s)=>{let t=e;return s.forEach((r,n)=>{t=t.replaceAll(r,n)}),t},ae=(e,s)=>{const t=new Map;return oe(s(ie(e,t).trimEnd()),t)},le=async(e,s,{langs:t=L,langAlias:r={},defaultLang:n,transformers:i=[],...o}={})=>{const l=o.logLevel??(s.env.isDebug?"debug":"warn"),c=l==="debug"?te(e):null,g=await U({langs:t,langAlias:r,themes:"themes"in o?Object.values(o.themes):[o.theme??"nord"]});await o.shikiSetup?.(g);const a=V(o),u=g.getLoadedLanguages();e.options.highlight=(m,d,f)=>ae(m,$=>g.codeToHtml($,{lang:re(d,u,n,l,c),meta:{__raw:f},transformers:[...a,...o.highlightLines??!0?[_(se(f))]:[],...X(f,o.whitespace),...i],..."themes"in o?{themes:o.themes,defaultColor:!1}:{theme:o.theme??"nord"}}))},N=/{([\d,-]+)}/,pe=e=>{const s=e.renderer.rules.fence;e.renderer.rules.fence=(...t)=>{const[r,n]=t,i=r[n],o=i.info||"",l=o.match(N);if(!l)return s(...t);i.info=o.replace(N,"").trim();const c=l[1];return i.info+=` ${c}`,s(...t)}},he=/<pre([\s\S]*?)style="([^"]*)"([^>]*)>/,ce=(e,{preWrapper:s=!0}={})=>{const t=e.renderer.rules.fence;e.renderer.rules.fence=(...r)=>{let n=t(...r);if(!n.startsWith("<pre"))return n;const[i,o,l]=r,c=i[o],g=c.info?e.utils.unescapeAll(c.info).trim():"",a=w(g),u=`${l.langPrefix}${a}`;if(!s)return n=n.replace(/<code[^]*?>/,"<code>"),n=`<pre class="${u}"${n.slice(4)}`,n;const m=ee(g,"title")||a;let d="";return n=n.replace(he,(f,$,W,E)=>(d=W.trim(),`<pre ${$.trim()}${E.trimEnd()}>`)),`<div class="${u}" data-highlighter="shiki" data-ext="${a}" data-title="${m}" style="${d}">${n}</div>`}},{url:h}=import.meta,ge=(e,{lineNumbers:s=!0,highlightLines:t=!0,collapsedLines:r="disable",notationDiff:n,notationErrorLevel:i,notationFocus:o,notationHighlight:l,notationWordHighlight:c,whitespace:g})=>{const a=[`import "${p("@vuepress/highlighter-helper/styles/base.css",h)}"`,`import "${p(`${y}/styles/shiki.css`,import.meta.url)}"`],u=[];s!=="disable"&&a.push(`import "${p("@vuepress/highlighter-helper/styles/line-numbers.css",h)}"`),(t||l)&&a.push(`import "${p("@vuepress/highlighter-helper/styles/notation-highlight.css",h)}"`),n&&a.push(`import "${p("@vuepress/highlighter-helper/styles/notation-diff.css",h)}"`),i&&a.push(`import "${p("@vuepress/highlighter-helper/styles/notation-error-level.css",h)}"`),o&&a.push(`import "${p("@vuepress/highlighter-helper/styles/notation-focus.css",h)}"`),l&&a.push(`import "${p("@vuepress/highlighter-helper/styles/notation-highlight.css",h)}"`),c&&a.push(`import "${p("@vuepress/highlighter-helper/styles/notation-word-highlight.css",h)}"`),g&&a.push(`import "${p("@vuepress/highlighter-helper/styles/whitespace.css",h)}"`),r!=="disable"&&(a.push(`import "${p("@vuepress/highlighter-helper/styles/collapsed-lines.css",h)}"`,`import { setupCollapsedLines } from "${p("@vuepress/highlighter-helper/composables/collapsedLines.js",h)}"`),u.push("setupCollapsedLines()"));let m=a.join(`
|
|
2
|
+
`);return u.length&&(m+=`
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
setup() {
|
|
6
|
+
${u.join(`
|
|
7
|
+
`)}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`),e.writeTemp("shiki/config.js",m)},A=(e={})=>{const s={preWrapper:!0,lineNumbers:!0,collapsedLines:"disable",...e};return{name:"@vuepress/plugin-shiki",extendsMarkdown:async(t,r)=>{const{code:n}=r.options.markdown;await le(t,r,{...x(n)?n:{},...e});const{preWrapper:i,lineNumbers:o,collapsedLines:l}=s;t.use(pe),t.use(ce,{preWrapper:i}),i&&(t.use(P,{lineNumbers:o}),t.use(T,{collapsedLines:l}))},clientConfigFile:t=>ge(t,s)}};export{L as bundledLanguageNames,we as bundledLanguages,A as default,A as shikiPlugin};
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/node/shiki.ts","../../src/node/transformers/vuepressTransformers.ts","../../src/node/transformers/getTransformers.ts","../../src/node/utils.ts","../../src/node/markdown/applyHighlighter/createMarkdownFilePathGetter.ts","../../src/node/markdown/applyHighlighter/getLanguage.ts","../../src/node/markdown/applyHighlighter/handleMustache.ts","../../src/node/markdown/applyHighlighter/index.ts","../../src/node/markdown/highlightLinesPlugin.ts","../../src/node/markdown/preWrapperPlugin.ts","../../src/node/prepareConfigFile.ts","../../src/node/shikiPlugin.ts"],"sourcesContent":["import { bundledLanguages } from 'shiki'\n\nexport { bundledLanguages } from 'shiki'\n\nexport const bundledLanguageNames = Object.keys(bundledLanguages)\n","import type { ShikiTransformer } from 'shiki'\n\nconst CODE_ESCAPE_RE = /\\[\\\\!code/g\n\nexport const addClassTransformer: ShikiTransformer = {\n name: 'vuepress:add-class',\n pre(node) {\n this.addClassToHast(node, 'vp-code')\n },\n}\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) {\n return code.replace(CODE_ESCAPE_RE, '[!code')\n },\n}\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","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): 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 defaultPosition: WhitespacePosition | boolean = false,\n): ShikiTransformer[] => {\n const position = resolveWhitespacePosition(meta, defaultPosition)\n // disable current code block\n if (position === false) return []\n\n return [transformerRenderWhitespace({ position })]\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 PLUGIN_NAME = '@vuepress/plugin-shiki'\n\nexport const logger = new Logger(PLUGIN_NAME)\n\nexport const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)\n\nexport const resolveLanguage = (info: string): string =>\n info\n .match(/^([^ :[{]+)/)?.[1]\n ?.replace(VUE_RE, '')\n .toLowerCase() ?? ''\n\nexport const resolveAttr = (info: string, attr: string): string | null => {\n // try to match specified attr mark\n const pattern = `\\\\b${attr}\\\\s*=\\\\s*(?<quote>['\"])(?<content>.+?)\\\\k<quote>(\\\\s|$)`\n const regex = new RegExp(pattern, 'i')\n const match = info.match(regex)\n\n // return content if matched, null if not specified\n return match?.groups?.content ?? null\n}\n\n/**\n * 2 steps:\n *\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 */\nexport const attrsToLines = (attrs: string): TransformerCompactLineOption[] => {\n const attrsContent = attrs.replace(/^(?:\\[.*?\\])?.*?([\\d,-]+).*/, '$1').trim()\n\n const result: number[] = []\n\n if (!attrsContent) {\n return []\n }\n\n attrsContent\n .split(',')\n .map((lineNumberConfig) =>\n lineNumberConfig.split('-').map((lineNumber) => 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 type MarkdownIt from 'markdown-it'\nimport type { MarkdownEnv } from 'vuepress/markdown'\n\nexport type MarkdownFilePathGetter = () => string\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) => {\n store.path = env.filePathRelative\n\n return rawRender(src, env)\n }\n\n return () => store.path || 'dynamic pages'\n}\n","import { isSpecialLang } from 'shiki'\nimport { colors } from 'vuepress/utils'\nimport { logger, resolveLanguage } from '../../utils.js'\nimport type { MarkdownFilePathGetter } from './createMarkdownFilePathGetter.js'\n\nconst WARNED_LANGS = new Set<string>()\n\nexport const getLanguage = (\n lang: string,\n loadedLanguages: string[],\n defaultLang: string | undefined,\n logLevel: string,\n getMarkdownFilePath: MarkdownFilePathGetter,\n): string => {\n let result = resolveLanguage(lang)\n\n if (result && !loadedLanguages.includes(result) && !isSpecialLang(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(getMarkdownFilePath())}`,\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 * @param str content\n * @param store mustache store\n * @returns\n */\nconst removeMustache = (str: string, store: MustacheStore): string =>\n str.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\nconst restoreMustache = (str: string, store: MustacheStore): string => {\n let result = str\n\n store.forEach((marker, match) => {\n result = result.replaceAll(marker, match)\n })\n\n return result\n}\n\nexport const handleMustache = (\n str: string,\n highlight: (str: string) => string,\n): string => {\n const store = new Map<string, string>()\n\n return restoreMustache(highlight(removeMustache(str, store).trimEnd()), store)\n}\n","import { transformerCompactLineOptions } from '@shikijs/transformers'\nimport type MarkdownIt from 'markdown-it'\nimport { createHighlighter } from 'shiki'\nimport type { App } from 'vuepress'\nimport { bundledLanguageNames } from '../../shiki.js'\nimport {\n getTransformers,\n whitespaceTransformer,\n} from '../../transformers/getTransformers.js'\nimport type { ShikiHighlightOptions } from '../../types.js'\nimport { attrsToLines } from '../../utils.js'\nimport { createMarkdownFilePathGetter } from './createMarkdownFilePathGetter.js'\nimport { getLanguage } from './getLanguage.js'\nimport { handleMustache } from './handleMustache.js'\n\nexport const applyHighlighter = async (\n md: MarkdownIt,\n app: App,\n {\n langs = bundledLanguageNames,\n langAlias = {},\n defaultLang,\n transformers: userTransformers = [],\n ...options\n }: ShikiHighlightOptions = {},\n): Promise<void> => {\n const logLevel = options.logLevel ?? (app.env.isDebug ? 'debug' : 'warn')\n const getMarkdownFilePath =\n logLevel === 'debug' ? createMarkdownFilePathGetter(md) : null\n\n const highlighter = await createHighlighter({\n langs,\n langAlias,\n themes:\n 'themes' in options\n ? Object.values(options.themes)\n : [options.theme ?? 'nord'],\n })\n\n await options.shikiSetup?.(highlighter)\n\n const transformers = getTransformers(options)\n const loadedLanguages = highlighter.getLoadedLanguages()\n\n md.options.highlight = (content, language, attrs) =>\n handleMustache(content, (str) =>\n highlighter.codeToHtml(str, {\n lang: getLanguage(\n language,\n loadedLanguages,\n defaultLang,\n logLevel,\n getMarkdownFilePath!,\n ),\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 ...whitespaceTransformer(attrs, options.whitespace),\n ...userTransformers,\n ],\n ...('themes' in options\n ? {\n themes: options.themes,\n defaultColor: false,\n }\n : { theme: options.theme ?? 'nord' }),\n }),\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 highlightLinesPlugin = (md: Markdown): void => {\n const rawFence = md.renderer.rules.fence!\n\n md.renderer.rules.fence = (...args) => {\n const [tokens, idx] = args\n const token = tokens[idx]\n\n const rawInfo = token.info || ''\n const result = rawInfo.match(HIGHLIGHT_LINES_REGEXP)\n\n if (!result) {\n return rawFence(...args)\n }\n\n // ensure the next plugin get the correct lang\n token.info = rawInfo.replace(HIGHLIGHT_LINES_REGEXP, '').trim()\n\n const lines = result[1]\n\n token.info += ` ${lines}`\n return rawFence(...args)\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 { resolveAttr, 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\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) => {\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 if (!preWrapper) {\n /**\n * remove `<code>` attributes\n *\n * In the source code of `markdown-it fence line 71, line 74`,\n * `fence` writes `class=\"language-*\"` onto the `code` element,\n * whereas in past versions, `vuepress` wrote it on the `pre` element.\n * Therefore, this behavior needs to be reset.\n *\n * Even though `shiki` directly returns the contents within `<pre>`\n * at `line 48` of `markdown-it`, I believe it is still prudent to make this adjustment.\n *\n * @see https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs\n */\n result = result.replace(/<code[^]*?>/, '<code>')\n result = `<pre class=\"${languageClass}\"${result.slice('<pre'.length)}`\n return result\n }\n\n const title = resolveAttr(info, 'title') || lang\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}\" data-title=\"${title}\" style=\"${styles}\">${result}</div>`\n }\n}\n","import { getRealPath } from '@vuepress/helper'\nimport type { App } from 'vuepress'\nimport type { ShikiPluginOptions } from './options.js'\nimport { PLUGIN_NAME } from './utils.js'\n\nconst { url } = import.meta\n\nexport const prepareConfigFile = (\n app: App,\n {\n lineNumbers = true,\n highlightLines = true,\n collapsedLines = 'disable',\n notationDiff,\n notationErrorLevel,\n notationFocus,\n notationHighlight,\n notationWordHighlight,\n whitespace,\n }: ShikiPluginOptions,\n): Promise<string> => {\n const imports: string[] = [\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/base.css', url)}\"`,\n `import \"${getRealPath(`${PLUGIN_NAME}/styles/shiki.css`, import.meta.url)}\"`,\n ]\n\n const setups: string[] = []\n\n if (lineNumbers !== 'disable') {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/line-numbers.css', url)}\"`,\n )\n }\n\n if (highlightLines || notationHighlight) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/notation-highlight.css', url)}\"`,\n )\n }\n\n if (notationDiff) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/notation-diff.css', url)}\"`,\n )\n }\n\n if (notationErrorLevel) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/notation-error-level.css', url)}\"`,\n )\n }\n\n if (notationFocus) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/notation-focus.css', url)}\"`,\n )\n }\n\n if (notationHighlight) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/notation-highlight.css', url)}\"`,\n )\n }\n\n if (notationWordHighlight) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/notation-word-highlight.css', url)}\"`,\n )\n }\n\n if (whitespace) {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/whitespace.css', url)}\"`,\n )\n }\n\n if (collapsedLines !== 'disable') {\n imports.push(\n `import \"${getRealPath('@vuepress/highlighter-helper/styles/collapsed-lines.css', url)}\"`,\n `import { setupCollapsedLines } from \"${getRealPath('@vuepress/highlighter-helper/composables/collapsedLines.js', url)}\"`,\n )\n setups.push('setupCollapsedLines()')\n }\n\n let code = imports.join('\\n')\n\n if (setups.length) {\n code += `\\n\nexport default {\n setup() {\n ${setups.join('\\n ')}\n }\n}\\n`\n }\n\n return app.writeTemp('shiki/config.js', code)\n}\n","import type {\n MarkdownItCollapsedLinesOptions,\n MarkdownItLineNumbersOptions,\n} from '@vuepress/highlighter-helper'\nimport {\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 type { MarkdownItPreWrapperOptions } from './markdown/index.js'\nimport {\n applyHighlighter,\n highlightLinesPlugin,\n preWrapperPlugin,\n} from './markdown/index.js'\nimport type { ShikiPluginOptions } from './options.js'\nimport { prepareConfigFile } from './prepareConfigFile.js'\n\nexport const shikiPlugin = (options: ShikiPluginOptions = {}): Plugin => {\n const opt: ShikiPluginOptions = {\n preWrapper: true,\n lineNumbers: true,\n collapsedLines: 'disable',\n ...options,\n }\n\n return {\n name: '@vuepress/plugin-shiki',\n\n extendsMarkdown: async (md, app) => {\n // FIXME: Remove in stable version\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const { code } = app.options.markdown\n\n await applyHighlighter(md, app, {\n ...(isPlainObject(code) ? code : {}),\n ...options,\n })\n\n const { preWrapper, lineNumbers, collapsedLines } = opt\n\n md.use(highlightLinesPlugin)\n md.use<MarkdownItPreWrapperOptions>(preWrapperPlugin, { preWrapper })\n if (preWrapper) {\n md.use<MarkdownItLineNumbersOptions>(lineNumbersPlugin, {\n lineNumbers,\n })\n md.use<MarkdownItCollapsedLinesOptions>(collapsedLinesPlugin, {\n collapsedLines,\n })\n }\n },\n\n clientConfigFile: (app) => prepareConfigFile(app, opt),\n }\n}\n"],"names":["bundledLanguageNames","bundledLanguages","CODE_ESCAPE_RE","addClassTransformer","node","cleanupTransformer","removeEscapeTransformer","code","emptyLineTransformer","hast","span","getTransformers","options","transformers","transformerNotationDiff","transformerNotationFocus","transformerNotationHighlight","transformerNotationErrorLevel","transformerNotationWordHighlight","transformerMetaWordHighlight","whitespaceTransformer","meta","defaultPosition","position","resolveWhitespacePosition","transformerRenderWhitespace","VUE_RE","PLUGIN_NAME","logger","Logger","nanoid","customAlphabet","resolveLanguage","info","resolveAttr","attr","pattern","regex","attrsToLines","attrs","attrsContent","result","lineNumberConfig","lineNumber","start","end","_","i","line","createMarkdownFilePathGetter","md","store","rawRender","src","env","WARNED_LANGS","getLanguage","lang","loadedLanguages","defaultLang","logLevel","getMarkdownFilePath","isSpecialLang","colors","MUSTACHE_REG","removeMustache","str","match","marker","restoreMustache","handleMustache","highlight","applyHighlighter","app","langs","langAlias","userTransformers","highlighter","createHighlighter","content","language","transformerCompactLineOptions","HIGHLIGHT_LINES_REGEXP","highlightLinesPlugin","rawFence","args","tokens","idx","token","rawInfo","lines","PRE_ATTRS_REGEXP","preWrapperPlugin","preWrapper","languageClass","title","styles","before","style","after","url","prepareConfigFile","lineNumbers","highlightLines","collapsedLines","notationDiff","notationErrorLevel","notationFocus","notationHighlight","notationWordHighlight","whitespace","imports","getRealPath","setups","shikiPlugin","opt","isPlainObject","lineNumbersPlugin","collapsedLinesPlugin"],"mappings":"qtBAIa,MAAAA,EAAuB,OAAO,KAAKC,CAAgB,ECF1DC,EAAiB,aAEVC,EAAwC,CACnD,KA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I,EAAIA,EAAO,CACjC,EAAA,GAAGK,CACL,CAAC,EAED,KAAM,CAAE,WAAAiF,EAAY,YAAAS,EAAa,eAAAE,CAAe,EAAIW,EAEpDjE,EAAG,IAAIiC,EAAoB,EAC3BjC,EAAG,IAAiC0C,GAAkB,CAAE,WAAAC,CAAW,CAAC,EAChEA,IACF3C,EAAG,IAAkCmE,EAAmB,CACtD,YAAAf,CACF,CAAC,EACDpD,EAAG,IAAqCoE,EAAsB,CAC5D,eAAAd,CACF,CAAC,EAEL,EAEA,iBAAmB/B,GAAQ4B,GAAkB5B,EAAK0C,CAAG,CACvD,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/plugin-shiki",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.52",
|
|
4
4
|
"description": "VuePress plugin - shiki",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"lib"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@shikijs/transformers": "^1.
|
|
36
|
-
"@vuepress/helper": "2.0.0-rc.
|
|
37
|
-
"@vuepress/highlighter-helper": "2.0.0-rc.
|
|
35
|
+
"@shikijs/transformers": "^1.21.0",
|
|
36
|
+
"@vuepress/helper": "2.0.0-rc.52",
|
|
37
|
+
"@vuepress/highlighter-helper": "2.0.0-rc.52",
|
|
38
38
|
"nanoid": "^5.0.7",
|
|
39
|
-
"shiki": "^1.
|
|
39
|
+
"shiki": "^1.21.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"vuepress": "2.0.0-rc.
|
|
42
|
+
"vuepress": "2.0.0-rc.17"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "0c0a6501082d7abdbfc4a3e4b6de48d902011c07"
|
|
48
48
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const createMarkdownFilePathGetter = (md) => {
|
|
2
|
-
const store = {};
|
|
3
|
-
const rawRender = md.render.bind(md);
|
|
4
|
-
// we need to store file path before each render
|
|
5
|
-
md.render = (src, env) => {
|
|
6
|
-
store.path = env.filePathRelative;
|
|
7
|
-
return rawRender(src, env);
|
|
8
|
-
};
|
|
9
|
-
return () => store.path || 'dynamic pages';
|
|
10
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isSpecialLang } from 'shiki';
|
|
2
|
-
import { colors } from 'vuepress/utils';
|
|
3
|
-
import { logger, resolveLanguage } from '../../utils.js';
|
|
4
|
-
const WARNED_LANGS = new Set();
|
|
5
|
-
export const getLanguage = (lang, loadedLanguages, defaultLang, logLevel, getMarkdownFilePath) => {
|
|
6
|
-
let result = resolveLanguage(lang);
|
|
7
|
-
if (result && !loadedLanguages.includes(result) && !isSpecialLang(result)) {
|
|
8
|
-
// warn for unknown languages only once
|
|
9
|
-
if (logLevel !== 'silent' && !WARNED_LANGS.has(result)) {
|
|
10
|
-
logger.warn(`Missing ${colors.cyan(lang)} highlighter, ${defaultLang ? `use ${colors.cyan(defaultLang)} to highlight instead.` : 'skip highlighting'}`);
|
|
11
|
-
WARNED_LANGS.add(result);
|
|
12
|
-
}
|
|
13
|
-
// log file path if unknown language is found
|
|
14
|
-
if (logLevel === 'debug') {
|
|
15
|
-
logger.info(`Unknown language ${colors.cyan(result)} found in ${colors.cyan(getMarkdownFilePath())}`);
|
|
16
|
-
}
|
|
17
|
-
result = defaultLang || 'plain';
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const handleMustache: (str: string, highlight: (str: string) => string) => string;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { nanoid } from '../../utils.js';
|
|
2
|
-
const MUSTACHE_REG = /\{\{[^]*?\}\}/g;
|
|
3
|
-
/**
|
|
4
|
-
* Replace mustache with unique markers
|
|
5
|
-
* @param str content
|
|
6
|
-
* @param store mustache store
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
const removeMustache = (str, store) => str.replace(MUSTACHE_REG, (match) => {
|
|
10
|
-
let marker = store.get(match);
|
|
11
|
-
if (!marker) {
|
|
12
|
-
marker = nanoid();
|
|
13
|
-
store.set(match, marker);
|
|
14
|
-
}
|
|
15
|
-
return marker;
|
|
16
|
-
});
|
|
17
|
-
const restoreMustache = (str, store) => {
|
|
18
|
-
let result = str;
|
|
19
|
-
store.forEach((marker, match) => {
|
|
20
|
-
result = result.replaceAll(marker, match);
|
|
21
|
-
});
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
export const handleMustache = (str, highlight) => {
|
|
25
|
-
const store = new Map();
|
|
26
|
-
return restoreMustache(highlight(removeMustache(str, store).trimEnd()), store);
|
|
27
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type MarkdownIt from 'markdown-it';
|
|
2
|
-
import type { App } from 'vuepress';
|
|
3
|
-
import type { ShikiHighlightOptions } from '../../types.js';
|
|
4
|
-
export declare const applyHighlighter: (md: MarkdownIt, app: App, { langs, langAlias, defaultLang, transformers: userTransformers, ...options }?: ShikiHighlightOptions) => Promise<void>;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { transformerCompactLineOptions } from '@shikijs/transformers';
|
|
2
|
-
import { createHighlighter } from 'shiki';
|
|
3
|
-
import { bundledLanguageNames } from '../../shiki.js';
|
|
4
|
-
import { getTransformers, whitespaceTransformer, } from '../../transformers/getTransformers.js';
|
|
5
|
-
import { attrsToLines } from '../../utils.js';
|
|
6
|
-
import { createMarkdownFilePathGetter } from './createMarkdownFilePathGetter.js';
|
|
7
|
-
import { getLanguage } from './getLanguage.js';
|
|
8
|
-
import { handleMustache } from './handleMustache.js';
|
|
9
|
-
export const applyHighlighter = async (md, app, { langs = bundledLanguageNames, langAlias = {}, defaultLang, transformers: userTransformers = [], ...options } = {}) => {
|
|
10
|
-
const logLevel = options.logLevel ?? (app.env.isDebug ? 'debug' : 'warn');
|
|
11
|
-
const getMarkdownFilePath = logLevel === 'debug' ? createMarkdownFilePathGetter(md) : null;
|
|
12
|
-
const highlighter = await createHighlighter({
|
|
13
|
-
langs,
|
|
14
|
-
langAlias,
|
|
15
|
-
themes: 'themes' in options
|
|
16
|
-
? Object.values(options.themes)
|
|
17
|
-
: [options.theme ?? 'nord'],
|
|
18
|
-
});
|
|
19
|
-
await options.shikiSetup?.(highlighter);
|
|
20
|
-
const transformers = getTransformers(options);
|
|
21
|
-
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
22
|
-
md.options.highlight = (content, language, attrs) => handleMustache(content, (str) => highlighter.codeToHtml(str, {
|
|
23
|
-
lang: getLanguage(language, loadedLanguages, defaultLang, logLevel, getMarkdownFilePath),
|
|
24
|
-
meta: {
|
|
25
|
-
/**
|
|
26
|
-
* Custom `transformers` passed by users may require `attrs`.
|
|
27
|
-
* e.g. [transformerNotationWordHighlight](https://shiki.style/packages/transformers#transformernotationwordhighlight)
|
|
28
|
-
*/
|
|
29
|
-
__raw: attrs,
|
|
30
|
-
},
|
|
31
|
-
transformers: [
|
|
32
|
-
...transformers,
|
|
33
|
-
...((options.highlightLines ?? true)
|
|
34
|
-
? [transformerCompactLineOptions(attrsToLines(attrs))]
|
|
35
|
-
: []),
|
|
36
|
-
...whitespaceTransformer(attrs, options.whitespace),
|
|
37
|
-
...userTransformers,
|
|
38
|
-
],
|
|
39
|
-
...('themes' in options
|
|
40
|
-
? {
|
|
41
|
-
themes: options.themes,
|
|
42
|
-
defaultColor: false,
|
|
43
|
-
}
|
|
44
|
-
: { theme: options.theme ?? 'nord' }),
|
|
45
|
-
}));
|
|
46
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Modified from https://github.com/egoist/markdown-it-highlight-lines
|
|
2
|
-
// Now this plugin is only used to normalize line attrs.
|
|
3
|
-
// The else part of line highlights logic is in '../highlight.ts'.
|
|
4
|
-
const HIGHLIGHT_LINES_REGEXP = /{([\d,-]+)}/;
|
|
5
|
-
export const highlightLinesPlugin = (md) => {
|
|
6
|
-
const rawFence = md.renderer.rules.fence;
|
|
7
|
-
md.renderer.rules.fence = (...args) => {
|
|
8
|
-
const [tokens, idx] = args;
|
|
9
|
-
const token = tokens[idx];
|
|
10
|
-
const rawInfo = token.info || '';
|
|
11
|
-
const result = rawInfo.match(HIGHLIGHT_LINES_REGEXP);
|
|
12
|
-
if (!result) {
|
|
13
|
-
return rawFence(...args);
|
|
14
|
-
}
|
|
15
|
-
// ensure the next plugin get the correct lang
|
|
16
|
-
token.info = rawInfo.replace(HIGHLIGHT_LINES_REGEXP, '').trim();
|
|
17
|
-
const lines = result[1];
|
|
18
|
-
token.info += ` ${lines}`;
|
|
19
|
-
return rawFence(...args);
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { resolveAttr, resolveLanguage } from '../utils.js';
|
|
2
|
-
const PRE_ATTRS_REGEXP = /<pre([\s\S]*?)style="([^"]*)"([^>]*)>/;
|
|
3
|
-
export const preWrapperPlugin = (md, { preWrapper = true } = {}) => {
|
|
4
|
-
const rawFence = md.renderer.rules.fence;
|
|
5
|
-
md.renderer.rules.fence = (...args) => {
|
|
6
|
-
let result = rawFence(...args);
|
|
7
|
-
if (!result.startsWith('<pre')) {
|
|
8
|
-
return result;
|
|
9
|
-
}
|
|
10
|
-
const [tokens, idx, options] = args;
|
|
11
|
-
const token = tokens[idx];
|
|
12
|
-
// get token info
|
|
13
|
-
const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
|
|
14
|
-
const lang = resolveLanguage(info);
|
|
15
|
-
const languageClass = `${options.langPrefix}${lang}`;
|
|
16
|
-
if (!preWrapper) {
|
|
17
|
-
/**
|
|
18
|
-
* remove `<code>` attributes
|
|
19
|
-
*
|
|
20
|
-
* In the source code of `markdown-it fence line 71, line 74`,
|
|
21
|
-
* `fence` writes `class="language-*"` onto the `code` element,
|
|
22
|
-
* whereas in past versions, `vuepress` wrote it on the `pre` element.
|
|
23
|
-
* Therefore, this behavior needs to be reset.
|
|
24
|
-
*
|
|
25
|
-
* Even though `shiki` directly returns the contents within `<pre>`
|
|
26
|
-
* at `line 48` of `markdown-it`, I believe it is still prudent to make this adjustment.
|
|
27
|
-
*
|
|
28
|
-
* @see https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs
|
|
29
|
-
*/
|
|
30
|
-
result = result.replace(/<code[^]*?>/, '<code>');
|
|
31
|
-
result = `<pre class="${languageClass}"${result.slice('<pre'.length)}`;
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
const title = resolveAttr(info, 'title') || lang;
|
|
35
|
-
let styles = '';
|
|
36
|
-
// before: maybe `v-pre class="shiki *"`
|
|
37
|
-
// after: style="*" tab-index="*"
|
|
38
|
-
result = result.replace(PRE_ATTRS_REGEXP, (_, before, style, after) => {
|
|
39
|
-
styles = style.trim();
|
|
40
|
-
// Keep `v-pre class="*"`, remove the rest.
|
|
41
|
-
return `<pre ${before.trim()}${after.trimEnd()}>`;
|
|
42
|
-
});
|
|
43
|
-
/**
|
|
44
|
-
* Add information to dataset for current code block.
|
|
45
|
-
*/
|
|
46
|
-
return `<div class="${languageClass}" data-highlighter="shiki" data-ext="${lang}" data-title="${title}" style="${styles}">${result}</div>`;
|
|
47
|
-
};
|
|
48
|
-
};
|
package/lib/node/options.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { MarkdownItCollapsedLinesOptions } from '@vuepress/highlighter-helper';
|
|
2
|
-
import type { PreWrapperOptions, ShikiHighlightOptions } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Options of @vuepress/plugin-shiki
|
|
5
|
-
*/
|
|
6
|
-
export type ShikiPluginOptions = Pick<MarkdownItCollapsedLinesOptions, 'collapsedLines'> & PreWrapperOptions & ShikiHighlightOptions & {
|
|
7
|
-
/**
|
|
8
|
-
* Line number options
|
|
9
|
-
*
|
|
10
|
-
* - A `boolean` value is to enable line numbers or not globally.
|
|
11
|
-
* - A `number` value is the minimum number of lines to enable line numbers
|
|
12
|
-
* - `disable` means completely disable the feature
|
|
13
|
-
*
|
|
14
|
-
* @default true
|
|
15
|
-
*/
|
|
16
|
-
lineNumbers?: boolean | number | 'disable';
|
|
17
|
-
};
|
package/lib/node/options.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { App } from 'vuepress';
|
|
2
|
-
import type { ShikiPluginOptions } from './options.js';
|
|
3
|
-
export declare const prepareConfigFile: (app: App, { lineNumbers, highlightLines, collapsedLines, notationDiff, notationErrorLevel, notationFocus, notationHighlight, notationWordHighlight, whitespace, }: ShikiPluginOptions) => Promise<string>;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getRealPath } from '@vuepress/helper';
|
|
2
|
-
import { PLUGIN_NAME } from './utils.js';
|
|
3
|
-
const { url } = import.meta;
|
|
4
|
-
export const prepareConfigFile = (app, { lineNumbers = true, highlightLines = true, collapsedLines = 'disable', notationDiff, notationErrorLevel, notationFocus, notationHighlight, notationWordHighlight, whitespace, }) => {
|
|
5
|
-
const imports = [
|
|
6
|
-
`import "${getRealPath('@vuepress/highlighter-helper/styles/base.css', url)}"`,
|
|
7
|
-
`import "${getRealPath(`${PLUGIN_NAME}/styles/shiki.css`, import.meta.url)}"`,
|
|
8
|
-
];
|
|
9
|
-
const setups = [];
|
|
10
|
-
if (lineNumbers !== 'disable') {
|
|
11
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/line-numbers.css', url)}"`);
|
|
12
|
-
}
|
|
13
|
-
if (highlightLines || notationHighlight) {
|
|
14
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-highlight.css', url)}"`);
|
|
15
|
-
}
|
|
16
|
-
if (notationDiff) {
|
|
17
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-diff.css', url)}"`);
|
|
18
|
-
}
|
|
19
|
-
if (notationErrorLevel) {
|
|
20
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-error-level.css', url)}"`);
|
|
21
|
-
}
|
|
22
|
-
if (notationFocus) {
|
|
23
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-focus.css', url)}"`);
|
|
24
|
-
}
|
|
25
|
-
if (notationHighlight) {
|
|
26
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-highlight.css', url)}"`);
|
|
27
|
-
}
|
|
28
|
-
if (notationWordHighlight) {
|
|
29
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-word-highlight.css', url)}"`);
|
|
30
|
-
}
|
|
31
|
-
if (whitespace) {
|
|
32
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/whitespace.css', url)}"`);
|
|
33
|
-
}
|
|
34
|
-
if (collapsedLines !== 'disable') {
|
|
35
|
-
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/collapsed-lines.css', url)}"`, `import { setupCollapsedLines } from "${getRealPath('@vuepress/highlighter-helper/composables/collapsedLines.js', url)}"`);
|
|
36
|
-
setups.push('setupCollapsedLines()');
|
|
37
|
-
}
|
|
38
|
-
let code = imports.join('\n');
|
|
39
|
-
if (setups.length) {
|
|
40
|
-
code += `\n
|
|
41
|
-
export default {
|
|
42
|
-
setup() {
|
|
43
|
-
${setups.join('\n ')}
|
|
44
|
-
}
|
|
45
|
-
}\n`;
|
|
46
|
-
}
|
|
47
|
-
return app.writeTemp('shiki/config.js', code);
|
|
48
|
-
};
|
package/lib/node/shiki.d.ts
DELETED
package/lib/node/shiki.js
DELETED
package/lib/node/shikiPlugin.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { collapsedLines as collapsedLinesPlugin, lineNumbers as lineNumbersPlugin, } from '@vuepress/highlighter-helper';
|
|
2
|
-
import { isPlainObject } from 'vuepress/shared';
|
|
3
|
-
import { applyHighlighter, highlightLinesPlugin, preWrapperPlugin, } from './markdown/index.js';
|
|
4
|
-
import { prepareConfigFile } from './prepareConfigFile.js';
|
|
5
|
-
export const shikiPlugin = (options = {}) => {
|
|
6
|
-
const opt = {
|
|
7
|
-
preWrapper: true,
|
|
8
|
-
lineNumbers: true,
|
|
9
|
-
collapsedLines: 'disable',
|
|
10
|
-
...options,
|
|
11
|
-
};
|
|
12
|
-
return {
|
|
13
|
-
name: '@vuepress/plugin-shiki',
|
|
14
|
-
extendsMarkdown: async (md, app) => {
|
|
15
|
-
// FIXME: Remove in stable version
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
17
|
-
const { code } = app.options.markdown;
|
|
18
|
-
await applyHighlighter(md, app, {
|
|
19
|
-
...(isPlainObject(code) ? code : {}),
|
|
20
|
-
...options,
|
|
21
|
-
});
|
|
22
|
-
const { preWrapper, lineNumbers, collapsedLines } = opt;
|
|
23
|
-
md.use(highlightLinesPlugin);
|
|
24
|
-
md.use(preWrapperPlugin, { preWrapper });
|
|
25
|
-
if (preWrapper) {
|
|
26
|
-
if (lineNumbers !== 'disable')
|
|
27
|
-
md.use(lineNumbersPlugin, { lineNumbers });
|
|
28
|
-
if (collapsedLines !== 'disable')
|
|
29
|
-
md.use(collapsedLinesPlugin, { collapsedLines });
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
clientConfigFile: (app) => prepareConfigFile(app, opt),
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { WhitespacePosition } from '@vuepress/highlighter-helper';
|
|
2
|
-
import type { ShikiTransformer } from 'shiki';
|
|
3
|
-
import type { ShikiHighlightOptions } from '../types.js';
|
|
4
|
-
export declare const getTransformers: (options: ShikiHighlightOptions) => ShikiTransformer[];
|
|
5
|
-
export declare const whitespaceTransformer: (meta: string, defaultPosition?: WhitespacePosition | boolean) => ShikiTransformer[];
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRenderWhitespace, } from '@shikijs/transformers';
|
|
2
|
-
import { resolveWhitespacePosition } from '@vuepress/highlighter-helper';
|
|
3
|
-
import { addClassTransformer, cleanupTransformer, emptyLineTransformer, removeEscapeTransformer, } from './vuepressTransformers.js';
|
|
4
|
-
export const getTransformers = (options) => {
|
|
5
|
-
const transformers = [];
|
|
6
|
-
if (options.notationDiff) {
|
|
7
|
-
transformers.push(transformerNotationDiff());
|
|
8
|
-
}
|
|
9
|
-
if (options.notationFocus) {
|
|
10
|
-
transformers.push(transformerNotationFocus({
|
|
11
|
-
classActiveLine: 'has-focus',
|
|
12
|
-
classActivePre: 'has-focused-lines',
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
if (options.notationHighlight) {
|
|
16
|
-
transformers.push(transformerNotationHighlight());
|
|
17
|
-
}
|
|
18
|
-
if (options.notationErrorLevel) {
|
|
19
|
-
transformers.push(transformerNotationErrorLevel());
|
|
20
|
-
}
|
|
21
|
-
if (options.notationWordHighlight) {
|
|
22
|
-
transformers.push(transformerNotationWordHighlight());
|
|
23
|
-
transformers.push(transformerMetaWordHighlight());
|
|
24
|
-
}
|
|
25
|
-
transformers.push(addClassTransformer, cleanupTransformer, removeEscapeTransformer, emptyLineTransformer);
|
|
26
|
-
return transformers;
|
|
27
|
-
};
|
|
28
|
-
export const whitespaceTransformer = (meta, defaultPosition = false) => {
|
|
29
|
-
const position = resolveWhitespacePosition(meta, defaultPosition);
|
|
30
|
-
// disable current code block
|
|
31
|
-
if (position === false)
|
|
32
|
-
return [];
|
|
33
|
-
return [transformerRenderWhitespace({ position })];
|
|
34
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ShikiTransformer } from 'shiki';
|
|
2
|
-
export declare const addClassTransformer: ShikiTransformer;
|
|
3
|
-
export declare const cleanupTransformer: ShikiTransformer;
|
|
4
|
-
/**
|
|
5
|
-
* This `transformer` is primarily for the usage instructions of themes.
|
|
6
|
-
* When developers need to provide an example like `// [!code xxx]`,
|
|
7
|
-
* they can use `// [\!code xxx]` to avoid being processed by `shiki`.
|
|
8
|
-
* After `shiki` completes the processing,
|
|
9
|
-
* replace `[\!code` back with `[!code` to display the correct text.
|
|
10
|
-
*/
|
|
11
|
-
export declare const removeEscapeTransformer: ShikiTransformer;
|
|
12
|
-
export declare const emptyLineTransformer: ShikiTransformer;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const CODE_ESCAPE_RE = /\[\\!code/g;
|
|
2
|
-
export const addClassTransformer = {
|
|
3
|
-
name: 'vuepress:add-class',
|
|
4
|
-
pre(node) {
|
|
5
|
-
this.addClassToHast(node, 'vp-code');
|
|
6
|
-
},
|
|
7
|
-
};
|
|
8
|
-
export const cleanupTransformer = {
|
|
9
|
-
name: 'vuepress:cleanup',
|
|
10
|
-
pre(node) {
|
|
11
|
-
delete node.properties.tabindex;
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* This `transformer` is primarily for the usage instructions of themes.
|
|
16
|
-
* When developers need to provide an example like `// [!code xxx]`,
|
|
17
|
-
* they can use `// [\!code xxx]` to avoid being processed by `shiki`.
|
|
18
|
-
* After `shiki` completes the processing,
|
|
19
|
-
* replace `[\!code` back with `[!code` to display the correct text.
|
|
20
|
-
*/
|
|
21
|
-
export const removeEscapeTransformer = {
|
|
22
|
-
name: 'vuepress:remove-escape',
|
|
23
|
-
postprocess(code) {
|
|
24
|
-
return code.replace(CODE_ESCAPE_RE, '[!code');
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
export const emptyLineTransformer = {
|
|
28
|
-
name: 'vuepress:empty-line',
|
|
29
|
-
code(hast) {
|
|
30
|
-
hast.children.forEach((span) => {
|
|
31
|
-
if (span.type === 'element' &&
|
|
32
|
-
span.tagName === 'span' &&
|
|
33
|
-
Array.isArray(span.properties.class) &&
|
|
34
|
-
span.properties.class.includes('line') &&
|
|
35
|
-
span.children.length === 0) {
|
|
36
|
-
span.children.push({
|
|
37
|
-
type: 'element',
|
|
38
|
-
tagName: 'wbr',
|
|
39
|
-
properties: {},
|
|
40
|
-
children: [],
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
};
|
package/lib/node/types.d.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { WhitespacePosition } from '@vuepress/highlighter-helper';
|
|
2
|
-
import type { BundledLanguage, BundledTheme, Highlighter, LanguageInput, ShikiTransformer, SpecialLanguage, StringLiteralUnion, ThemeRegistrationAny } from 'shiki';
|
|
3
|
-
export type ShikiLang = LanguageInput | SpecialLanguage | StringLiteralUnion<BundledLanguage>;
|
|
4
|
-
export type ShikiTheme = StringLiteralUnion<BundledTheme> | ThemeRegistrationAny;
|
|
5
|
-
export interface ShikiSingleThemeOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The single theme to use
|
|
8
|
-
*
|
|
9
|
-
* @see https://shiki.style/themes
|
|
10
|
-
*
|
|
11
|
-
* @default 'nord'
|
|
12
|
-
*/
|
|
13
|
-
theme?: ShikiTheme;
|
|
14
|
-
}
|
|
15
|
-
export interface ShikiDualThemeOptions {
|
|
16
|
-
/**
|
|
17
|
-
* The dark and light themes to use
|
|
18
|
-
*
|
|
19
|
-
* @see https://shiki.style/themes
|
|
20
|
-
*/
|
|
21
|
-
themes: {
|
|
22
|
-
dark: ShikiTheme;
|
|
23
|
-
light: ShikiTheme;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export type ShikiThemeOptions = ShikiDualThemeOptions | ShikiSingleThemeOptions;
|
|
27
|
-
export type ShikiHighlightOptions = ShikiThemeOptions & {
|
|
28
|
-
/**
|
|
29
|
-
* Languages to be loaded.
|
|
30
|
-
*
|
|
31
|
-
* Shiki does not preload any languages to avoid extra overhead. So you need
|
|
32
|
-
* to specify the languages you want to use.
|
|
33
|
-
*
|
|
34
|
-
* @see https://shiki.style/languages
|
|
35
|
-
*/
|
|
36
|
-
langs?: ShikiLang[];
|
|
37
|
-
/**
|
|
38
|
-
* Language alias
|
|
39
|
-
*
|
|
40
|
-
* @see https://shiki.style/guide/load-lang#custom-language-aliases
|
|
41
|
-
*/
|
|
42
|
-
langAlias?: Record<string, StringLiteralUnion<BundledLanguage>>;
|
|
43
|
-
/**
|
|
44
|
-
* Fallback language when the specified language is not available.
|
|
45
|
-
*
|
|
46
|
-
* @default 'plain'
|
|
47
|
-
*/
|
|
48
|
-
defaultLang?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Function to customize Shiki highlighter instance.
|
|
51
|
-
*/
|
|
52
|
-
shikiSetup?: (shiki: Highlighter) => Promise<void> | void;
|
|
53
|
-
/**
|
|
54
|
-
* Shiki transformers
|
|
55
|
-
*/
|
|
56
|
-
transformers?: ShikiTransformer[];
|
|
57
|
-
/**
|
|
58
|
-
* Enable highlight lines or not
|
|
59
|
-
*
|
|
60
|
-
* @default true
|
|
61
|
-
*/
|
|
62
|
-
highlightLines?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Enable notation diff transformer
|
|
65
|
-
*
|
|
66
|
-
* @default false
|
|
67
|
-
*
|
|
68
|
-
* @see https://shiki.style/packages/transformers#transformernotationdiff
|
|
69
|
-
*/
|
|
70
|
-
notationDiff?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Enable notation focus transformer
|
|
73
|
-
*
|
|
74
|
-
* @default false
|
|
75
|
-
*
|
|
76
|
-
* @see https://shiki.style/packages/transformers#transformernotationfocus
|
|
77
|
-
*/
|
|
78
|
-
notationFocus?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Enable notation highlight transformer
|
|
81
|
-
*
|
|
82
|
-
* @default false
|
|
83
|
-
*
|
|
84
|
-
* @see https://shiki.style/packages/transformers#transformernotationhighlight
|
|
85
|
-
*/
|
|
86
|
-
notationHighlight?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Enable notation error level transformer
|
|
89
|
-
*
|
|
90
|
-
* @default false
|
|
91
|
-
*
|
|
92
|
-
* @see https://shiki.style/packages/transformers#transformernotationerrorlevel
|
|
93
|
-
*/
|
|
94
|
-
notationErrorLevel?: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Enable notation word highlight transformer
|
|
97
|
-
*
|
|
98
|
-
* @default false
|
|
99
|
-
*
|
|
100
|
-
* @see https://shiki.style/packages/transformers#transformernotationwordhighlight
|
|
101
|
-
*/
|
|
102
|
-
notationWordHighlight?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Enable whitespace
|
|
105
|
-
* - true: enable render whitespace, same of `all`
|
|
106
|
-
* - false: disable render whitespace
|
|
107
|
-
* - 'all': render all whitespace
|
|
108
|
-
* - 'boundary': render leading and trailing whitespace of each line.
|
|
109
|
-
* - 'trailing': render trailing whitespace of each line
|
|
110
|
-
*
|
|
111
|
-
* you are able to use `:whitespace` or `:no-whitespace` or `:whitespace=position` to set single code block
|
|
112
|
-
*
|
|
113
|
-
* position: 'all' | 'boundary' | 'trailing'
|
|
114
|
-
*
|
|
115
|
-
* @default false
|
|
116
|
-
*
|
|
117
|
-
* @see https://shiki.style/packages/transformers#transformerrenderwhitespace
|
|
118
|
-
*/
|
|
119
|
-
whitespace?: WhitespacePosition | boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Log level Highlighter language detecter
|
|
122
|
-
*
|
|
123
|
-
* @description defaults to `'debug'` when `--debug` flag is enabled
|
|
124
|
-
*
|
|
125
|
-
* @default 'warn'
|
|
126
|
-
*/
|
|
127
|
-
logLevel?: 'debug' | 'silent' | 'warn';
|
|
128
|
-
};
|
|
129
|
-
export interface PreWrapperOptions {
|
|
130
|
-
/**
|
|
131
|
-
* Wrap the `<pre>` tag with an extra `<div>` or not. Do not disable it unless you
|
|
132
|
-
* understand what's it for
|
|
133
|
-
*
|
|
134
|
-
* - Required for `lineNumbers`
|
|
135
|
-
* - Required for title display of default theme
|
|
136
|
-
*/
|
|
137
|
-
preWrapper?: boolean;
|
|
138
|
-
}
|
package/lib/node/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/node/utils.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { TransformerCompactLineOption } from '@shikijs/transformers';
|
|
2
|
-
import { Logger } from '@vuepress/helper';
|
|
3
|
-
export declare const PLUGIN_NAME = "@vuepress/plugin-shiki";
|
|
4
|
-
export declare const logger: Logger;
|
|
5
|
-
export declare const nanoid: (size?: number) => string;
|
|
6
|
-
export declare const resolveLanguage: (info: string) => string;
|
|
7
|
-
export declare const resolveAttr: (info: string, attr: string) => string | null;
|
|
8
|
-
/**
|
|
9
|
-
* 2 steps:
|
|
10
|
-
*
|
|
11
|
-
* 1. convert attrs into line numbers:
|
|
12
|
-
* {4,7-13,16,23-27,40} -> [4,7,8,9,10,11,12,13,16,23,24,25,26,27,40]
|
|
13
|
-
* 2. convert line numbers into line options:
|
|
14
|
-
* [{ line: number, classes: string[] }]
|
|
15
|
-
*/
|
|
16
|
-
export declare const attrsToLines: (attrs: string) => TransformerCompactLineOption[];
|
package/lib/node/utils.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@vuepress/helper';
|
|
2
|
-
import { customAlphabet } from 'nanoid';
|
|
3
|
-
const VUE_RE = /-vue$/;
|
|
4
|
-
export const PLUGIN_NAME = '@vuepress/plugin-shiki';
|
|
5
|
-
export const logger = new Logger(PLUGIN_NAME);
|
|
6
|
-
export const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10);
|
|
7
|
-
export const resolveLanguage = (info) => info
|
|
8
|
-
.match(/^([^ :[{]+)/)?.[1]
|
|
9
|
-
?.replace(VUE_RE, '')
|
|
10
|
-
.toLowerCase() ?? '';
|
|
11
|
-
export const resolveAttr = (info, attr) => {
|
|
12
|
-
// try to match specified attr mark
|
|
13
|
-
const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`;
|
|
14
|
-
const regex = new RegExp(pattern, 'i');
|
|
15
|
-
const match = info.match(regex);
|
|
16
|
-
// return content if matched, null if not specified
|
|
17
|
-
return match?.groups?.content ?? null;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* 2 steps:
|
|
21
|
-
*
|
|
22
|
-
* 1. convert attrs into line numbers:
|
|
23
|
-
* {4,7-13,16,23-27,40} -> [4,7,8,9,10,11,12,13,16,23,24,25,26,27,40]
|
|
24
|
-
* 2. convert line numbers into line options:
|
|
25
|
-
* [{ line: number, classes: string[] }]
|
|
26
|
-
*/
|
|
27
|
-
export const attrsToLines = (attrs) => {
|
|
28
|
-
const attrsContent = attrs.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/, '$1').trim();
|
|
29
|
-
const result = [];
|
|
30
|
-
if (!attrsContent) {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
attrsContent
|
|
34
|
-
.split(',')
|
|
35
|
-
.map((lineNumberConfig) => lineNumberConfig.split('-').map((lineNumber) => parseInt(lineNumber, 10)))
|
|
36
|
-
.forEach(([start, end]) => {
|
|
37
|
-
if (start && end) {
|
|
38
|
-
result.push(...Array.from({ length: end - start + 1 }, (_, i) => start + i));
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
result.push(start);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return result.map((line) => ({
|
|
45
|
-
line,
|
|
46
|
-
classes: ['highlighted'],
|
|
47
|
-
}));
|
|
48
|
-
};
|