diff --git a/plugins/markdown/plugin-prismjs/src/node/markdown/highlightPlugin.ts b/plugins/markdown/plugin-prismjs/src/node/markdown/highlightPlugin.ts index 90febb0525..722f12533f 100644 --- a/plugins/markdown/plugin-prismjs/src/node/markdown/highlightPlugin.ts +++ b/plugins/markdown/plugin-prismjs/src/node/markdown/highlightPlugin.ts @@ -55,11 +55,6 @@ export const highlightPlugin = ( notationHighlight(parser) } - /** - * Add the `prismjs` class name to distinguish the highlight library used for the current code block. - */ - parser.pre.classList.push('prismjs') - parser.pre.classList.push(languageClass) return parser.stringify() diff --git a/plugins/markdown/plugin-prismjs/src/node/markdown/preWrapperPlugin.ts b/plugins/markdown/plugin-prismjs/src/node/markdown/preWrapperPlugin.ts index 1300b060f6..66491feffd 100644 --- a/plugins/markdown/plugin-prismjs/src/node/markdown/preWrapperPlugin.ts +++ b/plugins/markdown/plugin-prismjs/src/node/markdown/preWrapperPlugin.ts @@ -27,6 +27,9 @@ export const preWrapperPlugin = ( // resolve title from token info const title = resolveAttr(info, 'title') ?? language.ext - return `
Raw text
+"Raw text
-Raw text
+
Raw text
-Raw text
+
Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -47,43 +47,43 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers /
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers / :no-line-numbers > should work properly if \`lineNumbers\` is enabled by default 1`] = `
-"Raw text
+"Raw text
-Raw text
+
Raw text
-Raw text
+
Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -93,43 +93,43 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers /
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers / :no-line-numbers > should work properly if \`lineNumbers\` is set to a number by default 1`] = `
-"Raw text
+"Raw text
-Raw text
+
Raw text
-Raw text
+
Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -139,49 +139,49 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers /
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers=number > should work properly if \`lineNumbers\` is disabled by default 1`] = `
-"const line2 = 'line 2'
+"const line2 = 'line 2'
const line3 = 'line 3'
-const line3 = 'line 3'
+
const line3 = 'line 3'
const line4 = 'line 4'
const line5 = 'line 5'
-const line10 = 'line 10'
+
const line10 = 'line 10'
const line11 = 'line 11'
"
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers=number > should work properly if \`lineNumbers\` is enabled by default 1`] = `
-"const line2 = 'line 2'
+"const line2 = 'line 2'
const line3 = 'line 3'
-const line3 = 'line 3'
+
const line3 = 'line 3'
const line4 = 'line 4'
const line5 = 'line 5'
-const line10 = 'line 10'
+
const line10 = 'line 10'
const line11 = 'line 11'
"
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > :line-numbers=number > should work properly if \`lineNumbers\` is set to a number by default 1`] = `
-"const line2 = 'line 2'
+"const line2 = 'line 2'
const line3 = 'line 3'
-const line3 = 'line 3'
+
const line3 = 'line 3'
const line4 = 'line 4'
const line5 = 'line 5'
-const line10 = 'line 10'
+
const line10 = 'line 10'
const line11 = 'line 11'
"
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > highlight notation > should highlight notation 1`] = `
-"const foo = 'foo'
+"const foo = 'foo'
const bar = 'bar'
const baz = 'baz'
const qux = 'qux'
@@ -192,21 +192,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > highlight notati
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options > should disable \`highlightLines\` 1`] = `
-"Raw text
+"Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -221,21 +221,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options >
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options > should disable \`lineNumbers\` 1`] = `
-"Raw text
+"Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -250,21 +250,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options >
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options > should disable \`preWrapper\` 1`] = `
-"Raw text
+"Raw text
-const foo = 'foo'
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+const foo = 'foo'
function bar () {
return 1024
@@ -279,21 +279,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options >
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options > should enable \`lineNumbers\` according to number of code lines 1`] = `
-"Raw text
+"Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -308,21 +308,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options >
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options > should process code fences with default options 1`] = `
-"Raw text
+"Raw text
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -337,21 +337,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > plugin options >
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > syntax highlighting > should work if highlighted code is not wrapped with \`\` 1`] = `
-"highlighted code: Raw text
+"highlighted code: Raw text
, lang:
-highlighted code: const foo = 'foo'
+
highlighted code: const foo = 'foo'
function bar () {
return 1024
}
, lang: js
-highlighted code: const foo: string = 'foo'
+
highlighted code: const foo: string = 'foo'
function bar (): number {
return 1024
}
, lang: ts
-highlighted code:
+
highlighted code:
msg: {{msg}}
@@ -362,21 +362,21 @@ exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > syntax highlight
`;
exports[`@vuepress/plugin-prismjs > markdown fence preWrapper > syntax highlighting > should work if highlighted code is wrapped with \`\` 1`] = `
-"highlighted code: Raw text
+"highlighted code: Raw text
, lang:
-highlighted code: const foo = 'foo'
+
highlighted code: const foo = 'foo'
function bar () {
return 1024
}
, lang: js
-highlighted code: const foo: string = 'foo'
+
highlighted code: const foo: string = 'foo'
function bar (): number {
return 1024
}
, lang: ts
-highlighted code:
+
highlighted code:
msg: {{msg}}
diff --git a/plugins/markdown/plugin-shiki/src/node/markdown/preWrapperPlugin.ts b/plugins/markdown/plugin-shiki/src/node/markdown/preWrapperPlugin.ts
index 42a85df929..c82072d185 100644
--- a/plugins/markdown/plugin-shiki/src/node/markdown/preWrapperPlugin.ts
+++ b/plugins/markdown/plugin-shiki/src/node/markdown/preWrapperPlugin.ts
@@ -58,6 +58,9 @@ export const preWrapperPlugin = (
return ``
})
- return `${result}`
+ /**
+ * Add information to dataset for current code block.
+ */
+ return `${result}`
}
}
diff --git a/plugins/markdown/plugin-shiki/tests/__snapshots__/shiki-preWrapper.spec.ts.snap b/plugins/markdown/plugin-shiki/tests/__snapshots__/shiki-preWrapper.spec.ts.snap
index e8af6309eb..6852d9e6a8 100644
--- a/plugins/markdown/plugin-shiki/tests/__snapshots__/shiki-preWrapper.spec.ts.snap
+++ b/plugins/markdown/plugin-shiki/tests/__snapshots__/shiki-preWrapper.spec.ts.snap
@@ -1,35 +1,35 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers / :no-line-numbers > should work properly if \`lineNumbers\` is disabled by default 1`] = `
-"Raw text
-Raw text
-Raw text
-const foo = 'foo'
+"Raw text
+Raw text
+Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -38,35 +38,35 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers / :no-line-nu
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers / :no-line-numbers > should work properly if \`lineNumbers\` is enabled by default 1`] = `
-"Raw text
-Raw text
-Raw text
-const foo = 'foo'
+"Raw text
+Raw text
+Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -75,35 +75,35 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers / :no-line-nu
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers / :no-line-numbers > should work properly if \`lineNumbers\` is set to a number by default 1`] = `
-"Raw text
-Raw text
-Raw text
-const foo = 'foo'
+"Raw text
+Raw text
+Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -112,64 +112,64 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers / :no-line-nu
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers=number > should work properly if \`lineNumbers\` is disabled by default 1`] = `
-"const line2 = 'line 2'
+"const line2 = 'line 2'
const line3 = 'line 3'
-const line3 = 'line 3'
+
const line3 = 'line 3'
const line4 = 'line 4'
const line5 = 'line 5'
-const line10 = 'line 10'
+
const line10 = 'line 10'
const line11 = 'line 11'
"
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers=number > should work properly if \`lineNumbers\` is enabled by default 1`] = `
-"const line2 = 'line 2'
+"const line2 = 'line 2'
const line3 = 'line 3'
-const line3 = 'line 3'
+
const line3 = 'line 3'
const line4 = 'line 4'
const line5 = 'line 5'
-const line10 = 'line 10'
+
const line10 = 'line 10'
const line11 = 'line 11'
"
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > :line-numbers=number > should work properly if \`lineNumbers\` is set to a number by default 1`] = `
-"const line2 = 'line 2'
+"const line2 = 'line 2'
const line3 = 'line 3'
-const line3 = 'line 3'
+
const line3 = 'line 3'
const line4 = 'line 4'
const line5 = 'line 5'
-const line10 = 'line 10'
+
const line10 = 'line 10'
const line11 = 'line 11'
"
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > notation transformers > should work notation enabled 1`] = `
-"const foo = 'foo'
+"const foo = 'foo'
const bar = 'bar'
const baz = 'baz'
const bax = 'bax'
const buz = 'buz'
const qux = 'qux'
-
+
const foo = 'foo'
const bar = 'bar'
"
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should disable \`highlightLines\` 1`] = `
-"Raw text
-const foo = 'foo'
+"Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -178,24 +178,24 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should dis
const baz = () => {
return 2048
}
-console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
+console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
{{ inlineCode }}
"
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should disable \`lineNumbers\` 1`] = `
-"Raw text
-const foo = 'foo'
+"Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -204,7 +204,7 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should dis
const baz = () => {
return 2048
}
-console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
+console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
{{ inlineCode }}
"
`;
@@ -236,18 +236,18 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should dis
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should enable \`lineNumbers\` according to number of code lines 1`] = `
-"Raw text
-const foo = 'foo'
+"Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -256,24 +256,24 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should ena
const baz = () => {
return 2048
}
-console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
+console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
{{ inlineCode }}
"
`;
exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should process code fences with default options 1`] = `
-"Raw text
-const foo = 'foo'
+"Raw text
+const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
}
-const foo = 'foo'
+
const foo = 'foo'
function bar () {
return 1024
@@ -282,7 +282,7 @@ exports[`@vuepress/plugin-shiki > fence preWrapper > plugin options > should pro
const baz = () => {
return 2048
}
-console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
+console.log('1 + 2 + 3 =' + {{ 1 + 2 + 3 }})
{{ inlineCode }}
"
`;