Skip to content

Commit d0a20aa

Browse files
committed
feat(theme-default): add code-group custom container
1 parent e80cb13 commit d0a20aa

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

packages/@vuepress/theme-default/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
resolveActiveHeaderLinksPluginOptions,
66
resolveContainerPluginOptions,
77
resolveContainerPluginOptionsForDetails,
8+
resolveContainerPluginOptionsForCodeGroup,
9+
resolveContainerPluginOptionsForCodeGroupItem,
810
resolveDebugPluginOptions,
911
resolveGitPluginOptions,
1012
resolveMediumZoomPluginOptions,
@@ -43,6 +45,14 @@ export const defaultTheme: Theme<DefaultThemeOptions> = (options, app) => {
4345
],
4446
['@vuepress/container', resolveContainerPluginOptions(options, 'danger')],
4547
['@vuepress/container', resolveContainerPluginOptionsForDetails(options)],
48+
[
49+
'@vuepress/container',
50+
resolveContainerPluginOptionsForCodeGroup(options),
51+
],
52+
[
53+
'@vuepress/container',
54+
resolveContainerPluginOptionsForCodeGroupItem(options),
55+
],
4656
['@vuepress/debug', resolveDebugPluginOptions(options, app)],
4757
['@vuepress/git', resolveGitPluginOptions(options)],
4858
['@vuepress/medium-zoom', resolveMediumZoomPluginOptions(options)],

packages/@vuepress/theme-default/src/node/resolveContainerPluginOptions.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,41 @@ export const resolveContainerPluginOptionsForDetails = (
5454
after: () => '</details>\n',
5555
}
5656
}
57+
58+
/**
59+
* Resolve options for @vuepress/plugin-container
60+
*
61+
* For code-group block
62+
*/
63+
export const resolveContainerPluginOptionsForCodeGroup = (
64+
options: DefaultThemeOptions
65+
): ContainerPluginOptions | boolean => {
66+
if (options.themePlugins?.container?.codeGroup === false) {
67+
return false
68+
}
69+
70+
return {
71+
type: 'code-group',
72+
before: () => `<CodeGroup>\n`,
73+
after: () => '</CodeGroup>\n',
74+
}
75+
}
76+
77+
/**
78+
* Resolve options for @vuepress/plugin-container
79+
*
80+
* For code-group-item block
81+
*/
82+
export const resolveContainerPluginOptionsForCodeGroupItem = (
83+
options: DefaultThemeOptions
84+
): ContainerPluginOptions | boolean => {
85+
if (options.themePlugins?.container?.codeGroupItem === false) {
86+
return false
87+
}
88+
89+
return {
90+
type: 'code-group-item',
91+
before: (info) => `<CodeGroupItem title="${info}">\n`,
92+
after: () => '</CodeGroupItem>\n',
93+
}
94+
}

packages/@vuepress/theme-default/src/types/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface DefaultThemeOptions
2626
warning?: boolean
2727
danger?: boolean
2828
details?: boolean
29+
codeGroup?: boolean
30+
codeGroupItem?: boolean
2931
}
3032

3133
/**

0 commit comments

Comments
 (0)