Skip to content

Commit b2d7b9a

Browse files
committed
Merge branch 'main' into plugin-git-component
2 parents fb31e25 + c53b423 commit b2d7b9a

File tree

35 files changed

+1581
-1203
lines changed

35 files changed

+1581
-1203
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@vueuse/core": "^12.7.0",
4141
"katex": "0.16.21",
4242
"mathjax-full": "3.2.2",
43-
"sass-embedded": "^1.85.0",
43+
"sass-embedded": "^1.85.1",
4444
"sass-loader": "^16.0.5",
4545
"vue": "^3.5.13",
4646
"vuepress": "catalog:"

docs/plugins/markdown/prismjs.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,36 @@ body > div {
400400
}
401401
```
402402

403+
### codeBlockTitle
404+
405+
- Type: `boolean | CodeBlockTitleRender`
406+
407+
```ts
408+
type CodeBlockTitleRender = (title: string, code: string) => string
409+
```
410+
411+
- Default: `true`
412+
413+
- Details: Whether to enable code block title rendering. Add `title="Title"` after the code block <code>\`\`\`</code> to set the title.
414+
415+
Pass `CodeBlockTitleRender` to customize the title rendering.
416+
417+
- Example:
418+
419+
**Input:**
420+
421+
````md {1}
422+
```ts title="foo/baz.js"
423+
console.log('hello')
424+
```
425+
````
426+
427+
**Output:**
428+
429+
```ts title="foo/baz.js"
430+
console.log('hello')
431+
```
432+
403433
::: tip
404434
405435
In the new version, some functionalities similar to [shiki](https://shiki.style/packages/transformers) have been implemented, allowing you to style code blocks using the same syntax.

docs/plugins/markdown/shiki.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,36 @@ body > div {
394394
}
395395
```
396396

397+
### codeBlockTitle
398+
399+
- Type: `boolean | CodeBlockTitleRender`
400+
401+
```ts
402+
type CodeBlockTitleRender = (title: string, code: string) => string
403+
```
404+
405+
- Default: `true`
406+
407+
- Details: Whether to enable code block title rendering. Add `title="Title"` after the code block <code>\`\`\`</code> to set the title.
408+
409+
Pass `CodeBlockTitleRender` to customize the title rendering.
410+
411+
- Example:
412+
413+
**Input:**
414+
415+
````md {1}
416+
```ts title="foo/baz.js"
417+
console.log('hello')
418+
```
419+
````
420+
421+
**Output:**
422+
423+
```ts title="foo/baz.js"
424+
console.log('hello')
425+
```
426+
397427
### notationDiff
398428
399429
- Type: `boolean`

docs/zh/plugins/markdown/prismjs.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,36 @@ body > div {
400400
}
401401
```
402402

403+
### codeBlockTitle
404+
405+
- 类型:`boolean | CodeBlockTitleRender`
406+
407+
```ts
408+
type CodeBlockTitleRender = (title: string, code: string) => string
409+
```
410+
411+
- 默认值:`true`
412+
413+
- 详情:是否启用代码块标题渲染。在代码块 <code>\`\`\`</code> 后面添加 `title="标题"` 来设置标题。
414+
415+
传入 `CodeBlockTitleRender` 以自定义标题渲染。
416+
417+
- 示例:
418+
419+
**输入:**
420+
421+
````md {1}
422+
```ts title="foo/baz.js"
423+
console.log('hello')
424+
```
425+
````
426+
427+
**输出:**
428+
429+
```ts title="foo/baz.js"
430+
console.log('hello')
431+
```
432+
403433
::: tip
404434
405435
在新的版本中,实现了类似于 [shiki](https://shiki.style/packages/transformers) 的部分功能,

docs/zh/plugins/markdown/shiki.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,36 @@ body > div {
396396
}
397397
```
398398

399+
### codeBlockTitle
400+
401+
- 类型:`boolean | CodeBlockTitleRender`
402+
403+
```ts
404+
type CodeBlockTitleRender = (title: string, code: string) => string
405+
```
406+
407+
- 默认值:`true`
408+
409+
- 详情:是否启用代码块标题渲染。在代码块 <code>\`\`\`</code> 后面添加 `title="标题"` 来设置标题。
410+
411+
传入 `CodeBlockTitleRender` 以自定义标题渲染。
412+
413+
- 示例:
414+
415+
**输入:**
416+
417+
````md {1}
418+
```ts title="foo/baz.js"
419+
console.log('hello')
420+
```
421+
````
422+
423+
**输出:**
424+
425+
```ts title="foo/baz.js"
426+
console.log('hello')
427+
```
428+
399429
### notationDiff
400430
401431
- 类型:`boolean`

e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@vuepress/plugin-theme-data": "workspace:*",
3131
"@vuepress/plugin-watermark": "workspace:*",
3232
"@vuepress/theme-default": "workspace:*",
33-
"sass-embedded": "^1.85.0",
33+
"sass-embedded": "^1.85.1",
3434
"sass-loader": "^16.0.5",
3535
"vue": "^3.5.13",
3636
"vuepress": "catalog:"

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
"@commitlint/cli": "^19.7.1",
3535
"@commitlint/config-conventional": "^19.7.1",
3636
"@lerna-lite/cli": "^3.12.1",
37-
"@lerna-lite/publish": "^3.12.1",
37+
"@lerna-lite/publish": "^3.12.2",
3838
"@rollup/plugin-commonjs": "^28.0.2",
3939
"@rollup/plugin-node-resolve": "^16.0.0",
40-
"@types/node": "^22.13.5",
40+
"@types/node": "^22.13.9",
4141
"@types/webpack-env": "^1.18.8",
42-
"@vitest/coverage-istanbul": "3.0.6",
42+
"@vitest/coverage-istanbul": "3.0.7",
4343
"conventional-changelog-cli": "^5.0.0",
4444
"cpx2": "^8.0.0",
4545
"cross-env": "^7.0.3",
@@ -49,26 +49,26 @@
4949
"husky": "^9.1.7",
5050
"nano-staged": "^0.8.0",
5151
"postcss-html": "^1.8.0",
52-
"prettier": "^3.5.2",
52+
"prettier": "^3.5.3",
5353
"prettier-config-vuepress": "^5.0.0",
5454
"rimraf": "^6.0.1",
55-
"rollup": "^4.34.8",
55+
"rollup": "^4.34.9",
5656
"rollup-plugin-dts": "^6.1.1",
57-
"rollup-plugin-esbuild": "^6.2.0",
57+
"rollup-plugin-esbuild": "^6.2.1",
5858
"rollup-plugin-resolve-shebang": "^1.0.1",
59-
"sass-embedded": "^1.85.0",
60-
"sort-package-json": "^2.14.0",
61-
"stylelint": "^16.14.1",
59+
"sass-embedded": "^1.85.1",
60+
"sort-package-json": "^2.15.1",
61+
"stylelint": "^16.15.0",
6262
"stylelint-config-hope": "^8.0.0",
6363
"stylelint-config-html": "^1.1.0",
6464
"tsconfig-vuepress": "^5.2.1",
6565
"tsx": "^4.19.3",
66-
"typescript": "^5.7.3",
66+
"typescript": "^5.8.2",
6767
"vite": "~6.1.1",
68-
"vitest": "3.0.6",
68+
"vitest": "3.0.7",
6969
"vuepress": "catalog:"
7070
},
71-
"packageManager": "pnpm@10.4.1",
71+
"packageManager": "pnpm@10.5.2",
7272
"engines": {
7373
"node": "^18.19.0 || >= 20.6.0"
7474
},

plugins/markdown/plugin-prismjs/src/node/markdown/preWrapperPlugin.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Markdown } from 'vuepress/markdown'
2-
import { resolveAttr, resolveLanguage } from '../utils/index.js'
2+
import { resolveLanguage } from '../utils/index.js'
33

44
export interface MarkdownItPreWrapperOptions {
55
/**
@@ -33,12 +33,9 @@ export const preWrapperPlugin = (
3333
const language = resolveLanguage(info)
3434
const languageClass = `${langPrefix}${language.name}`
3535

36-
// resolve title from token info
37-
const title = resolveAttr(info, 'title') ?? language.ext
38-
3936
/**
4037
* Add information to dataset for current code block.
4138
*/
42-
return `<div class="${languageClass}" data-highlighter="prismjs" data-ext="${language.ext}" data-title="${title}">${result.replace(` class="${languageClass}"`, '')}</div>`
39+
return `<div class="${languageClass}" data-highlighter="prismjs" data-ext="${language.ext}">${result.replace(` class="${languageClass}"`, '')}</div>`
4340
}
4441
}

plugins/markdown/plugin-prismjs/src/node/options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
MarkdownItCodeBlockTitleOptions,
23
MarkdownItCollapsedLinesOptions,
34
MarkdownItLineNumbersOptions,
45
} from '@vuepress/highlighter-helper'
@@ -11,7 +12,8 @@ import type { PrismjsHighlightOptions } from './types.js'
1112
/**
1213
* Options of @vuepress/plugin-prismjs
1314
*/
14-
export type PrismjsPluginOptions = MarkdownItLineNumbersOptions &
15+
export type PrismjsPluginOptions = MarkdownItCodeBlockTitleOptions &
16+
MarkdownItLineNumbersOptions &
1517
MarkdownItPreWrapperOptions &
1618
MarkdownItPrismjsHighlightOptions &
1719
Pick<MarkdownItCollapsedLinesOptions, 'collapsedLines'> &

plugins/markdown/plugin-prismjs/src/node/prepareClientConfigFile.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const prepareClientConfigFile = (
1111
lineNumbers = true,
1212
highlightLines = true,
1313
collapsedLines = 'disable',
14+
codeBlockTitle = true,
1415
notationDiff,
1516
notationErrorLevel,
1617
notationFocus,
@@ -88,6 +89,12 @@ export const prepareClientConfigFile = (
8889
setups.push('setupCollapsedLines()')
8990
}
9091

92+
if (codeBlockTitle) {
93+
imports.push(
94+
`import "${getModulePath('@vuepress/highlighter-helper/styles/code-block-title.css', import.meta)}"`,
95+
)
96+
}
97+
9198
let code = imports.join('\n')
9299

93100
if (setups.length) {

plugins/markdown/plugin-prismjs/src/node/prismjsPlugin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
codeBlockTitle as codeBlockTitlePlugin,
23
collapsedLines as collapsedLinesPlugin,
34
lineNumbers as lineNumbersPlugin,
45
} from '@vuepress/highlighter-helper'
@@ -15,14 +16,21 @@ export const prismjsPlugin = (options: PrismjsPluginOptions = {}): Plugin => {
1516
preWrapper: true,
1617
lineNumbers: true,
1718
collapsedLines: false,
19+
codeBlockTitle: true,
1820
...options,
1921
}
2022

2123
return {
2224
name: '@vuepress/plugin-prismjs',
2325

2426
extendsMarkdown(md) {
25-
const { preloadLanguages, preWrapper, lineNumbers, collapsedLines } = opt
27+
const {
28+
preloadLanguages,
29+
preWrapper,
30+
lineNumbers,
31+
collapsedLines,
32+
codeBlockTitle,
33+
} = opt
2634

2735
if (preloadLanguages?.length) {
2836
loadLanguages(preloadLanguages)
@@ -40,6 +48,8 @@ export const prismjsPlugin = (options: PrismjsPluginOptions = {}): Plugin => {
4048
md.use(lineNumbersPlugin, { lineNumbers, removeLastLine: true })
4149
if (collapsedLines !== 'disable')
4250
md.use(collapsedLinesPlugin, { collapsedLines, removeLastLine: true })
51+
52+
md.use(codeBlockTitlePlugin, { codeBlockTitle })
4353
}
4454
},
4555

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './escapeRegExp.js'
22
export * from './languages.js'
33
export * from './resolveLanguage.js'
4-
export * from './resolveAttr.js'

0 commit comments

Comments
 (0)