Vuepress-Plugin-Clipboard

Vuepress2在新窗口打开 插件:添加代码块复制按钮,代码一键复制

Vuepress2在新窗口打开 plugin: generate code copy button | code clipboard



awesome-vuepressgithub
npmnpm-downloadnpm-size

  • vue3 + ts + setup 改进
  • 减轻light主题中的过渡动画
  • 添加了更多class,样式和响应式的支持 提供样式自定义

Current Site Source Code(当前站点示例源码)在新窗口打开

Install

npm install -D vuepress-plugin-clipboard
yarn add -D vuepress-plugin-clipboard
pnpm add -D vuepress-plugin-clipboard

Usage

// .vuepress/config.js
import { clipboardPlugin } from 'vuepress-plugin-clipboard'
module.exports = {
  plugins: [
    clipboardPlugin({
      // options ...
    })
  ]
}
// .vuepress/config.ts
import { defineUserConfig } from 'vuepress'
import { clipboardPlugin } from 'vuepress-plugin-clipboard'

export default defineUserConfig({
  plugins: [
    clipboardPlugin({
      // options ...
    })
  ]
})

Options

optiontypedefaultinfo
staticIconbooleanfalseCopy icon is only visible when hovering over code block or is always visible.

复制按钮是否设置为悬停时可见
selectorstring'div[class*="language-"]'This is the CSS selector to which the copy button component will be attached.

目标代码块的CSS选择器
delaynumber400Page animation delay(ms). Affect the generation of buttons when rendering

页面动画的延迟毫秒, 这会影响到渲染时的按钮生成
colorstring"var(--c-brand)"This sets the color of the copy button and can take any hex code.

复制按钮的颜色, 可以使用任意的十六进制颜色代码
backgroundTransitionbooleantrueEnables the background transition animation of the attached code block when a user presses the copy button.

点击复制按钮时是否启动过渡动画
backgroundTransitionColorstring"var(--code-bg-color)"This sets the color of the background transition animation and can take any hex code.

过渡动画背景颜色, 可以使用任意的十六进制颜色代码
successTextstring"Copied!"Setting the text that displays when a user presses the copy button.

复制成功后的提示词
successTextColorstring"var(--c-brand-light)"This sets the color of the text that displays when a user presses the copy button

设置提示词的颜色, 可以使用任意的十六进制颜色代码


I just try my best to make thing well, Could you give a ⭐ star ⭐在新窗口打开 to encourage me ?