CodePen
将 CodePen 项目嵌入到 VitePress 页面中。
安装
sh
pnpm add vitepress-plugin-codepensh
npm install vitepress-plugin-codepensh
bun add vitepress-plugin-codepensh
deno add vitepress-plugin-codepensh
yarn add vitepress-plugin-codepen使用
vitepress-tuck 模式 推荐
ts
import { defineConfig } from 'vitepress-tuck'
import codepen from 'vitepress-plugin-codepen'
export default defineConfig({
plugins: [codepen()],
})传统模式
ts
import { defineConfig } from 'vitepress'
import { codepenPlugin } from 'vitepress-plugin-codepen'
export default defineConfig({
markdown: {
config: (md) => {
md.use(codepenPlugin)
},
},
})ts
import type { Theme } from 'vitepress'
import { enhanceAppWithCodepen } from 'vitepress-plugin-codepen/client'
import DefaultTheme from 'vitepress/theme'
export default {
extends: DefaultTheme,
enhanceApp(ctx) {
enhanceAppWithCodepen(ctx)
},
} satisfies Theme语法
基本用法
md
@[codepen](user/slash)带配置的用法
md
@[codepen preview editable title="示例" height="400px" tab="css,result" theme="dark"](leimapapa/RwOZQOW)属性说明
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
title | string | - | 标题 |
user | string | - | CodePen 用户名(从链接解析) |
slash | string | - | Pen 标识符(从链接解析) |
tab | string | 'result' | 默认显示的标签页 |
theme | string | - | 主题 |
preview | boolean | false | 预览模式 |
editable | boolean | false | 可编辑模式 |
width | string | '100%' | 宽度 |
height | string | - | 高度 |
示例
md
@[codepen](leimapapa/RwOZQOW)