@vuepress/plugin-shiki 2.0.0-rc.31 → 2.0.0-rc.32
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.
|
@@ -2,20 +2,35 @@ import { resolveAttr, resolveLanguage } from '../utils.js';
|
|
|
2
2
|
export const preWrapperPlugin = (md, { preWrapper = true } = {}) => {
|
|
3
3
|
const rawFence = md.renderer.rules.fence;
|
|
4
4
|
md.renderer.rules.fence = (...args) => {
|
|
5
|
+
let result = rawFence(...args);
|
|
6
|
+
if (!result.startsWith('<pre')) {
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
5
9
|
const [tokens, idx, options] = args;
|
|
6
10
|
const token = tokens[idx];
|
|
7
11
|
// get token info
|
|
8
12
|
const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
|
|
9
13
|
const lang = resolveLanguage(info);
|
|
10
|
-
const title = resolveAttr(info, 'title') || lang;
|
|
11
14
|
const languageClass = `${options.langPrefix}${lang}`;
|
|
12
|
-
let result = rawFence(...args);
|
|
13
15
|
if (!preWrapper) {
|
|
14
|
-
|
|
16
|
+
/**
|
|
17
|
+
* remove `<code>` attributes
|
|
18
|
+
*
|
|
19
|
+
* In the source code of `markdown-it fence line 71, line 74`,
|
|
20
|
+
* `fence` writes `class="language-*"` onto the `code` element,
|
|
21
|
+
* whereas in past versions, `vuepress` wrote it on the `pre` element.
|
|
22
|
+
* Therefore, this behavior needs to be reset.
|
|
23
|
+
*
|
|
24
|
+
* Even though `shiki` directly returns the contents within `<pre>`
|
|
25
|
+
* at `line 48` of `markdown-it`, I believe it is still prudent to make this adjustment.
|
|
26
|
+
*
|
|
27
|
+
* @see https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs
|
|
28
|
+
*/
|
|
15
29
|
result = result.replace(/<code[^]*?>/, '<code>');
|
|
16
30
|
result = `<pre class="${languageClass}"${result.slice('<pre'.length)}`;
|
|
17
31
|
return result;
|
|
18
32
|
}
|
|
33
|
+
const title = resolveAttr(info, 'title') || lang;
|
|
19
34
|
return `<div class="${languageClass}" data-ext="${lang}" data-title="${title}">${result}</div>`;
|
|
20
35
|
};
|
|
21
36
|
};
|
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.32",
|
|
4
4
|
"description": "VuePress plugin - shiki",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"@types/markdown-it": "^14.1.1",
|
|
50
50
|
"markdown-it": "^14.1.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "ae404292432a5ecdc0aa2d1553a7c24273a8c4c3"
|
|
53
53
|
}
|