diff --git a/docs/2.preview/主题效果预览.md b/docs/2.preview/主题效果预览.md index f9f9de03..bf7cd47e 100644 --- a/docs/2.preview/主题效果预览.md +++ b/docs/2.preview/主题效果预览.md @@ -104,6 +104,23 @@ H~2~O - twitter - +**demo wrapper** + +::: demo-wrapper + + +
+
main
+
aside
+
+ +::: + **代码** ```js diff --git a/theme/src/client/styles/md-enhance.scss b/theme/src/client/styles/md-enhance.scss index 2dbde338..dbd7a1e7 100644 --- a/theme/src/client/styles/md-enhance.scss +++ b/theme/src/client/styles/md-enhance.scss @@ -415,3 +415,63 @@ } } } + +/* --------------------- demo-wrapper ------------------------ */ + +.plume-content .demo-wrapper { + min-height: 40px; + margin: 40px -16px; + border: solid 1px var(--vp-c-divider); + border-radius: 8px; + box-shadow: var(--vp-shadow-2); + + .demo-head { + display: flex; + gap: 5px; + align-items: center; + justify-content: flex-start; + padding: 5px 0 5px 8px; + border-bottom: solid 1px var(--vp-c-divider); + } + + .demo-head i { + display: inline-block; + width: 10px; + height: 10px; + background: #ccc; + border-radius: 100%; + + &:nth-child(1) { + background-color: var(--vp-c-danger-3); + } + + &:nth-child(2) { + background-color: var(--vp-c-warning-3); + } + + &:nth-child(3) { + background-color: var(--vp-c-green-3); + } + } + + .demo-container { + padding: 10px 20px; + background-color: var(--vp-c-bg-alt); + border-bottom-right-radius: 8px; + border-bottom-left-radius: 8px; + + > :first-of-type { + margin-top: 0; + } + + > :last-of-type { + margin-bottom: 0; + } + } +} + +@media (min-width: 419px) { + .plume-content .demo-wrapper { + margin: 40px 0; + } +} diff --git a/theme/src/node/container.ts b/theme/src/node/container.ts new file mode 100644 index 00000000..5231ce12 --- /dev/null +++ b/theme/src/node/container.ts @@ -0,0 +1,14 @@ +import containerPlugin from '@vuepress/plugin-container' +import type { Plugin } from '@vuepress/core' + +export const customContainers: Plugin[] = [ + containerPlugin({ + type: 'demo-wrapper', + before() { + return `
\n` + }, + after() { + return '
\n' + }, + }), +] diff --git a/theme/src/node/plugins.ts b/theme/src/node/plugins.ts index 157d80c4..c1c9486a 100644 --- a/theme/src/node/plugins.ts +++ b/theme/src/node/plugins.ts @@ -31,6 +31,7 @@ import { resolveLocaleOptions } from './resolveLocaleOptions.js' import { pathJoin } from './utils.js' import { resolveNotesList } from './resolveNotesList.js' import { resolvedDocsearchOption, resolvedSearchOptions } from './searchPluginOptions.js' +import { customContainers } from './container.js' export function setupPlugins( app: App, @@ -88,6 +89,8 @@ export function setupPlugins( delay: 200, offset: 20, }), + + ...customContainers, ] if (options.readingTime !== false)