@vuepress/plugin-shiki 2.0.0-rc.41 → 2.0.0-rc.43
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/markdown/applyHighlighter/createMarkdownFilePathGetter.js +1 -1
- package/lib/node/markdown/applyHighlighter/handleMustache.js +3 -2
- package/lib/node/markdown/applyHighlighter/index.js +1 -1
- package/lib/node/markdown/highlightLinesPlugin.js +4 -5
- package/lib/node/options.d.ts +1 -1
- package/lib/node/shikiPlugin.js +1 -0
- package/lib/node/transformers/getTransformers.d.ts +1 -1
- package/lib/node/types.d.ts +5 -5
- package/lib/node/utils.js +4 -4
- package/package.json +7 -7
|
@@ -15,10 +15,11 @@ const removeMustache = (str, store) => str.replace(MUSTACHE_REG, (match) => {
|
|
|
15
15
|
return marker;
|
|
16
16
|
});
|
|
17
17
|
const restoreMustache = (str, store) => {
|
|
18
|
+
let result = str;
|
|
18
19
|
store.forEach((marker, match) => {
|
|
19
|
-
|
|
20
|
+
result = result.replaceAll(marker, match);
|
|
20
21
|
});
|
|
21
|
-
return
|
|
22
|
+
return result;
|
|
22
23
|
};
|
|
23
24
|
export const handleMustache = (str, highlight) => {
|
|
24
25
|
const store = new Map();
|
|
@@ -19,7 +19,7 @@ export const applyHighlighter = async (md, app, { langs = bundledLanguageNames,
|
|
|
19
19
|
await options.shikiSetup?.(highlighter);
|
|
20
20
|
const transformers = getTransformers(options);
|
|
21
21
|
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
22
|
-
md.options.highlight = (
|
|
22
|
+
md.options.highlight = (content, language, attrs) => handleMustache(content, (str) => highlighter.codeToHtml(str, {
|
|
23
23
|
lang: getLanguage(language, loadedLanguages, defaultLang, logLevel, getMarkdownFilePath),
|
|
24
24
|
meta: {
|
|
25
25
|
/**
|
|
@@ -7,16 +7,15 @@ export const highlightLinesPlugin = (md) => {
|
|
|
7
7
|
md.renderer.rules.fence = (...args) => {
|
|
8
8
|
const [tokens, idx] = args;
|
|
9
9
|
const token = tokens[idx];
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const result = rawInfo?.match(HIGHLIGHT_LINES_REGEXP);
|
|
10
|
+
const rawInfo = token.info || '';
|
|
11
|
+
const result = rawInfo.match(HIGHLIGHT_LINES_REGEXP);
|
|
13
12
|
if (!result) {
|
|
14
13
|
return rawFence(...args);
|
|
15
14
|
}
|
|
16
15
|
// ensure the next plugin get the correct lang
|
|
17
16
|
token.info = rawInfo.replace(HIGHLIGHT_LINES_REGEXP, '').trim();
|
|
18
|
-
lines = result[1];
|
|
19
|
-
token.info +=
|
|
17
|
+
const lines = result[1];
|
|
18
|
+
token.info += ` ${lines}`;
|
|
20
19
|
return rawFence(...args);
|
|
21
20
|
};
|
|
22
21
|
};
|
package/lib/node/options.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import type { PreWrapperOptions, ShikiHighlightOptions } from './types.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Options of @vuepress/plugin-shiki
|
|
5
5
|
*/
|
|
6
|
-
export type ShikiPluginOptions =
|
|
6
|
+
export type ShikiPluginOptions = Pick<MarkdownItLineNumbersOptions, 'lineNumbers'> & PreWrapperOptions & ShikiHighlightOptions;
|
package/lib/node/shikiPlugin.js
CHANGED
|
@@ -6,6 +6,7 @@ export const shikiPlugin = ({ preWrapper = true, lineNumbers = true, ...options
|
|
|
6
6
|
name: '@vuepress/plugin-shiki',
|
|
7
7
|
extendsMarkdown: async (md, app) => {
|
|
8
8
|
// FIXME: Remove in stable version
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
9
10
|
const { code } = app.options.markdown;
|
|
10
11
|
await applyHighlighter(md, app, {
|
|
11
12
|
...(isPlainObject(code) ? code : {}),
|
|
@@ -2,4 +2,4 @@ import type { WhitespacePosition } from '@vuepress/highlighter-helper';
|
|
|
2
2
|
import type { ShikiTransformer } from 'shiki';
|
|
3
3
|
import type { ShikiHighlightOptions } from '../types.js';
|
|
4
4
|
export declare const getTransformers: (options: ShikiHighlightOptions) => ShikiTransformer[];
|
|
5
|
-
export declare const whitespaceTransformer: (meta: string, defaultPosition?:
|
|
5
|
+
export declare const whitespaceTransformer: (meta: string, defaultPosition?: WhitespacePosition | boolean) => ShikiTransformer[];
|
package/lib/node/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WhitespacePosition } from '@vuepress/highlighter-helper';
|
|
2
2
|
import type { BundledLanguage, BundledTheme, Highlighter, LanguageInput, ShikiTransformer, SpecialLanguage, StringLiteralUnion, ThemeRegistrationAny } from 'shiki';
|
|
3
|
-
export type ShikiLang = LanguageInput | StringLiteralUnion<BundledLanguage
|
|
4
|
-
export type ShikiTheme =
|
|
3
|
+
export type ShikiLang = LanguageInput | SpecialLanguage | StringLiteralUnion<BundledLanguage>;
|
|
4
|
+
export type ShikiTheme = StringLiteralUnion<BundledTheme> | ThemeRegistrationAny;
|
|
5
5
|
export interface ShikiSingleThemeOptions {
|
|
6
6
|
/**
|
|
7
7
|
* The single theme to use
|
|
@@ -49,7 +49,7 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
|
|
|
49
49
|
/**
|
|
50
50
|
* Function to customize Shiki highlighter instance.
|
|
51
51
|
*/
|
|
52
|
-
shikiSetup?: (shiki: Highlighter) => void |
|
|
52
|
+
shikiSetup?: (shiki: Highlighter) => Promise<void> | void;
|
|
53
53
|
/**
|
|
54
54
|
* Shiki transformers
|
|
55
55
|
*/
|
|
@@ -116,7 +116,7 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
|
|
|
116
116
|
*
|
|
117
117
|
* @see https://shiki.style/packages/transformers#transformerrenderwhitespace
|
|
118
118
|
*/
|
|
119
|
-
whitespace?:
|
|
119
|
+
whitespace?: WhitespacePosition | boolean;
|
|
120
120
|
/**
|
|
121
121
|
* Log level Highlighter language detecter
|
|
122
122
|
*
|
|
@@ -124,7 +124,7 @@ export type ShikiHighlightOptions = ShikiThemeOptions & {
|
|
|
124
124
|
*
|
|
125
125
|
* @default 'warn'
|
|
126
126
|
*/
|
|
127
|
-
logLevel?: '
|
|
127
|
+
logLevel?: 'debug' | 'silent' | 'warn';
|
|
128
128
|
};
|
|
129
129
|
export interface PreWrapperOptions {
|
|
130
130
|
/**
|
package/lib/node/utils.js
CHANGED
|
@@ -25,14 +25,14 @@ export const resolveAttr = (info, attr) => {
|
|
|
25
25
|
* [{ line: number, classes: string[] }]
|
|
26
26
|
*/
|
|
27
27
|
export const attrsToLines = (attrs) => {
|
|
28
|
-
|
|
28
|
+
const attrsContent = attrs.replace(/^(?:\[.*?\])?.*?([\d,-]+).*/, '$1').trim();
|
|
29
29
|
const result = [];
|
|
30
|
-
if (!
|
|
30
|
+
if (!attrsContent) {
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
attrsContent
|
|
34
34
|
.split(',')
|
|
35
|
-
.map((
|
|
35
|
+
.map((lineNumberConfig) => lineNumberConfig.split('-').map((lineNumber) => parseInt(lineNumber, 10)))
|
|
36
36
|
.forEach(([start, end]) => {
|
|
37
37
|
if (start && end) {
|
|
38
38
|
result.push(...Array.from({ length: end - start + 1 }, (_, i) => start + i));
|
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.43",
|
|
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.16.3",
|
|
36
|
+
"@vuepress/helper": "2.0.0-rc.43",
|
|
37
|
+
"@vuepress/highlighter-helper": "2.0.0-rc.43",
|
|
38
38
|
"nanoid": "^5.0.7",
|
|
39
|
-
"shiki": "^1.
|
|
39
|
+
"shiki": "^1.16.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"vuepress": "2.0.0-rc.
|
|
42
|
+
"vuepress": "2.0.0-rc.15"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "7c75a58f6aed788e2ee40e2b2f0451a76ec20a23"
|
|
48
48
|
}
|