Code Copy

Mr.Hope ... February 27, 2021 00:07 Feature
  • Copy code
  • Feature
Less than 1 minute

If you are a programmer, you may want your users to be able to copy the code you show in the text with one click.

For this, vuepress-theme-hope includes @mr-hope/copy-code (opens new window), which provides a copy button on code blocks.

# Usage

After enabling, this plugin will automatically add a copy button to the bottom right corner of each code block.

By default, the button is only displayed on desktop mode. To display this button on mobile devices, set showInMobile to true.

After user press the copy button, a success hint will display on the screen. The default hint duration is 2000ms, to change the duration, please set duration in options (ms). To disable the hint, set duration to 0.

# Effect

// .vuepress/config.js
module.exports = {
  themeConfig: {
    copyCode: {},
  },
};
1
2
3
4
5
6