@vuepress/plugin-shiki 2.0.0-rc.37 → 2.0.0-rc.39
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/client/styles/shiki.css +19 -0
- package/lib/node/markdown/applyHighlighter/getLanguage.d.ts +1 -1
- package/lib/node/markdown/applyHighlighter/getLanguage.js +2 -2
- package/lib/node/markdown/applyHighlighter/index.js +4 -4
- package/lib/node/prepareConfigFile.d.ts +3 -0
- package/lib/node/prepareConfigFile.js +28 -0
- package/lib/node/shikiPlugin.js +3 -0
- package/package.json +7 -6
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--code-c-text: #9e9e9e;
|
|
3
|
+
--code-c-bg: #282c34;
|
|
4
|
+
--code-highlight-bg-color: rgb(0 0 0 / 66%);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.shiki span {
|
|
8
|
+
color: var(--shiki-light, inherit);
|
|
9
|
+
}
|
|
10
|
+
[data-theme=dark] .shiki span {
|
|
11
|
+
color: var(--shiki-dark, inherit);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
div[data-highlighter=shiki] {
|
|
15
|
+
background-color: var(--shiki-light-bg, var(--code-c-bg));
|
|
16
|
+
}
|
|
17
|
+
[data-theme=dark] div[data-highlighter=shiki] {
|
|
18
|
+
background-color: var(--shiki-dark-bg, var(--code-c-bg));
|
|
19
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { MarkdownFilePathGetter } from './createMarkdownFilePathGetter.js';
|
|
2
|
-
export declare const getLanguage: (lang: string, loadedLanguages: string[], defaultLang: string, logLevel: string, getMarkdownFilePath: MarkdownFilePathGetter) => string;
|
|
2
|
+
export declare const getLanguage: (lang: string, loadedLanguages: string[], defaultLang: string | undefined, logLevel: string, getMarkdownFilePath: MarkdownFilePathGetter) => string;
|
|
@@ -7,14 +7,14 @@ export const getLanguage = (lang, loadedLanguages, defaultLang, logLevel, getMar
|
|
|
7
7
|
if (result && !loadedLanguages.includes(result) && !isSpecialLang(result)) {
|
|
8
8
|
// warn for unknown languages only once
|
|
9
9
|
if (logLevel !== 'silent' && !WARNED_LANGS.has(result)) {
|
|
10
|
-
logger.warn(`Missing ${colors.cyan(lang)} highlighter, use ${colors.cyan(defaultLang)} to highlight instead.`);
|
|
10
|
+
logger.warn(`Missing ${colors.cyan(lang)} highlighter, ${defaultLang ? `use ${colors.cyan(defaultLang)} to highlight instead.` : 'skip highlighting'}`);
|
|
11
11
|
WARNED_LANGS.add(result);
|
|
12
12
|
}
|
|
13
13
|
// log file path if unknown language is found
|
|
14
14
|
if (logLevel === 'debug') {
|
|
15
15
|
logger.info(`Unknown language ${colors.cyan(result)} found in ${colors.cyan(getMarkdownFilePath())}`);
|
|
16
16
|
}
|
|
17
|
-
result = defaultLang;
|
|
17
|
+
result = defaultLang || 'plain';
|
|
18
18
|
}
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { transformerCompactLineOptions } from '@shikijs/transformers';
|
|
2
|
-
import {
|
|
2
|
+
import { createHighlighter } from 'shiki';
|
|
3
3
|
import { bundledLanguageNames } from '../../shiki.js';
|
|
4
4
|
import { getTransformers, whitespaceTransformer, } from '../../transformers/getTransformers.js';
|
|
5
5
|
import { attrsToLines } from '../../utils.js';
|
|
6
6
|
import { createMarkdownFilePathGetter } from './createMarkdownFilePathGetter.js';
|
|
7
7
|
import { getLanguage } from './getLanguage.js';
|
|
8
8
|
import { handleMustache } from './handleMustache.js';
|
|
9
|
-
export const applyHighlighter = async (md, app, { langs = bundledLanguageNames, langAlias = {}, defaultLang
|
|
9
|
+
export const applyHighlighter = async (md, app, { langs = bundledLanguageNames, langAlias = {}, defaultLang, transformers: userTransformers = [], ...options } = {}) => {
|
|
10
10
|
const logLevel = options.logLevel ?? (app.env.isDebug ? 'debug' : 'warn');
|
|
11
11
|
const getMarkdownFilePath = logLevel === 'debug' ? createMarkdownFilePathGetter(md) : null;
|
|
12
|
-
const highlighter = await
|
|
12
|
+
const highlighter = await createHighlighter({
|
|
13
13
|
langs,
|
|
14
14
|
langAlias,
|
|
15
15
|
themes: 'themes' in options
|
|
@@ -30,7 +30,7 @@ export const applyHighlighter = async (md, app, { langs = bundledLanguageNames,
|
|
|
30
30
|
},
|
|
31
31
|
transformers: [
|
|
32
32
|
...transformers,
|
|
33
|
-
...(options.highlightLines ?? true
|
|
33
|
+
...((options.highlightLines ?? true)
|
|
34
34
|
? [transformerCompactLineOptions(attrsToLines(attrs))]
|
|
35
35
|
: []),
|
|
36
36
|
...whitespaceTransformer(attrs, options.whitespace),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getRealPath } from '@vuepress/helper';
|
|
2
|
+
import { PLUGIN_NAME } from './utils.js';
|
|
3
|
+
const { url } = import.meta;
|
|
4
|
+
export const prepareConfigFile = (app, options) => {
|
|
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
|
+
if (options.notationDiff) {
|
|
10
|
+
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-diff.css', url)}"`);
|
|
11
|
+
}
|
|
12
|
+
if (options.notationErrorLevel) {
|
|
13
|
+
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-error-level.css', url)}"`);
|
|
14
|
+
}
|
|
15
|
+
if (options.notationFocus) {
|
|
16
|
+
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-focus.css', url)}"`);
|
|
17
|
+
}
|
|
18
|
+
if (options.notationHighlight) {
|
|
19
|
+
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-highlight.css', url)}"`);
|
|
20
|
+
}
|
|
21
|
+
if (options.notationWordHighlight) {
|
|
22
|
+
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/notation-word-highlight.css', url)}"`);
|
|
23
|
+
}
|
|
24
|
+
if (options.whitespace) {
|
|
25
|
+
imports.push(`import "${getRealPath('@vuepress/highlighter-helper/styles/whitespace.css', url)}"`);
|
|
26
|
+
}
|
|
27
|
+
return app.writeTemp('shiki/config.js', imports.join('\n'));
|
|
28
|
+
};
|
package/lib/node/shikiPlugin.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { lineNumbers as lineNumbersPlugin } from '@vuepress/highlighter-helper';
|
|
2
2
|
import { isPlainObject } from 'vuepress/shared';
|
|
3
3
|
import { applyHighlighter, highlightLinesPlugin, preWrapperPlugin, } from './markdown/index.js';
|
|
4
|
+
import { prepareConfigFile } from './prepareConfigFile.js';
|
|
4
5
|
export const shikiPlugin = ({ preWrapper = true, lineNumbers = true, ...options } = {}) => ({
|
|
5
6
|
name: '@vuepress/plugin-shiki',
|
|
6
7
|
extendsMarkdown: async (md, app) => {
|
|
8
|
+
// FIXME: Remove in stable version
|
|
7
9
|
const { code } = app.options.markdown;
|
|
8
10
|
await applyHighlighter(md, app, {
|
|
9
11
|
...(isPlainObject(code) ? code : {}),
|
|
@@ -15,4 +17,5 @@ export const shikiPlugin = ({ preWrapper = true, lineNumbers = true, ...options
|
|
|
15
17
|
md.use(lineNumbersPlugin, { lineNumbers });
|
|
16
18
|
}
|
|
17
19
|
},
|
|
20
|
+
clientConfigFile: (app) => prepareConfigFile(app, options),
|
|
18
21
|
});
|
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.39",
|
|
4
4
|
"description": "VuePress plugin - shiki",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./lib/node/index.js",
|
|
26
|
+
"./styles/*": "./lib/client/styles/*",
|
|
26
27
|
"./package.json": "./package.json"
|
|
27
28
|
},
|
|
28
29
|
"main": "./lib/node/index.js",
|
|
@@ -31,11 +32,11 @@
|
|
|
31
32
|
"lib"
|
|
32
33
|
],
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@shikijs/transformers": "^1.
|
|
35
|
-
"@vuepress/helper": "2.0.0-rc.
|
|
36
|
-
"@vuepress/highlighter-helper": "2.0.0-rc.
|
|
35
|
+
"@shikijs/transformers": "^1.10.3",
|
|
36
|
+
"@vuepress/helper": "2.0.0-rc.39",
|
|
37
|
+
"@vuepress/highlighter-helper": "2.0.0-rc.39",
|
|
37
38
|
"nanoid": "^5.0.7",
|
|
38
|
-
"shiki": "^1.
|
|
39
|
+
"shiki": "^1.10.3"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"vuepress": "2.0.0-rc.14"
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "5fc0740210318a083a02e8bfcd31fdde5b2f88ac"
|
|
47
48
|
}
|