-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
911 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# copy-code | ||
|
||
<NpmBadge package="@vuepress/plugin-copy-code" /> | ||
|
||
This plugin will automatically add a copy button to the top right corner of each code block on PC devices. | ||
|
||
The default selector matches `@vuepress/theme-default`, so you might need to change it when integrating your own theme. | ||
|
||
## Usage | ||
|
||
```bash | ||
npm i -D @vuepress/plugin-copy-code@next | ||
``` | ||
|
||
```ts | ||
import { copyCodePlugin } from '@vuepress/plugin-copy-code' | ||
|
||
export default { | ||
plugins: [ | ||
copyCodePlugin({ | ||
// options | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
### selector | ||
|
||
- Type: `string | string[]` | ||
- Default: `'.theme-default-content div[class*="language-"] pre'` | ||
- Details: | ||
|
||
Code block selector | ||
|
||
### showInMobile | ||
|
||
- Type: `boolean` | ||
- Default: `false` | ||
- Details: | ||
|
||
Whether to display copy button on the mobile device | ||
|
||
### duration | ||
|
||
- Type: `number` | ||
- Default: `2000` | ||
- Details: | ||
|
||
Hint display time, setting it to `0` will disable the hint. | ||
|
||
### delay | ||
|
||
- Type: `number` | ||
- Default: `800` | ||
- Details: | ||
|
||
The delay of registering copy code buttons, in ms. | ||
|
||
If the theme you are using has a switching animation, it is recommended to configure this option to `Switch animation duration + 200`. | ||
|
||
### locales | ||
|
||
- Type: `CopyCodeLocaleConfig` | ||
|
||
```ts | ||
interface CopyCodeLocaleData { | ||
/** | ||
* Copy text | ||
*/ | ||
copy: string | ||
|
||
/** | ||
* Copied text | ||
*/ | ||
copied: string | ||
} | ||
|
||
interface CopyCodeLocaleConfig { | ||
[localePath: string]: CopyCodeLocaleData | ||
} | ||
``` | ||
|
||
- Required: No | ||
|
||
- Details: | ||
|
||
Locales config for copy code plugin. | ||
|
||
- Example: | ||
|
||
```ts | ||
import { copyCodePlugin } from "vuepress-plugin-copy-code2"; | ||
|
||
export default { | ||
locales: { | ||
"/": { | ||
// this is a supported language | ||
lang: "en-US", | ||
}, | ||
"/xx/": { | ||
// the plugin does not support this language | ||
lang: "mm-NN", | ||
}, | ||
}, | ||
|
||
plugins: [ | ||
copyCodePlugin({ | ||
locales: { | ||
"/": { | ||
// Override copy button label text | ||
copy: "Copy Codes from code block", | ||
}, | ||
|
||
"/xx/": { | ||
// Complete locale config for `mm-NN` language here | ||
}, | ||
}, | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
::: details Built-in Supported Languages | ||
|
||
- **Simplified Chinese** (zh-CN) | ||
- **Traditional Chinese** (zh-TW) | ||
- **English (United States)** (en-US) | ||
- **German** (de-DE) | ||
- **German (Australia)** (de-AT) | ||
- **Russian** (ru-RU) | ||
- **Ukrainian** (uk-UA) | ||
- **Vietnamese** (vi-VN) | ||
- **Portuguese (Brazil)** (pt-BR) | ||
- **Polish** (pl-PL) | ||
- **French** (fr-FR) | ||
- **Spanish** (es-ES) | ||
- **Slovak** (sk-SK) | ||
- **Japanese** (ja-JP) | ||
- **Turkish** (tr-TR) | ||
- **Korean** (ko-KR) | ||
- **Finnish** (fi-FI) | ||
- **Indonesian** (id-ID) | ||
- **Dutch** (nl-NL) | ||
|
||
::: | ||
|
||
## Styles | ||
|
||
You can customize the icon of the *copy button* via CSS variables: | ||
|
||
@[code css](@vuepress/plugin-copy-code/src/client/styles/vars.css) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# copy-code | ||
|
||
<NpmBadge package="@vuepress/plugin-copy-code" /> | ||
|
||
此插件会自动在 PC 设备上为每个代码块右上角添加复制按钮。 | ||
|
||
默认选择器匹配 `@vuepress/theme-default`,所以在你自己的主题中集成时可能需要调整它。 | ||
|
||
## 使用 | ||
|
||
```bash | ||
npm i -D @vuepress/plugin-copy-code@next | ||
``` | ||
|
||
```ts | ||
import { copyCodePlugin } from '@vuepress/plugin-copy-code' | ||
|
||
export default { | ||
plugins: [ | ||
copyCodePlugin({ | ||
// options | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
## 使用方法 | ||
|
||
### selector | ||
|
||
- 类型: `string | string[]` | ||
- 默认值: `'.theme-default-content div[class*="language-"] pre'` | ||
- 详情: | ||
|
||
代码块选择器 | ||
|
||
### showInMobile | ||
|
||
- 类型: `boolean` | ||
- 默认值: `false` | ||
- 详情: | ||
|
||
是否展示在移动端 | ||
|
||
### duration | ||
|
||
- 类型: `number` | ||
- 默认值: `2000` | ||
- 详情: | ||
|
||
提示消息显示时间,设置为 `0` 会禁用提示。 | ||
|
||
### delay | ||
|
||
- 类型: `number` | ||
- 默认值: `800` | ||
- 详情: | ||
|
||
注册复制按钮的延时,单位 ms。 | ||
|
||
如果你使用的主题有切换动画,建议配置此选项为 `切换动画时长 + 200` | ||
|
||
### locales | ||
|
||
- 类型: `CopyCodeLocaleConfig` | ||
|
||
```ts | ||
interface CopyCodeLocaleData { | ||
/** | ||
* 复制文字 | ||
*/ | ||
copy: string; | ||
|
||
/** | ||
* 已复制文字 | ||
*/ | ||
copied: string; | ||
} | ||
|
||
interface CopyCodeLocaleConfig { | ||
[localePath: string]: CopyCodeLocaleData; | ||
} | ||
``` | ||
|
||
- 必填: 否 | ||
- 详情: | ||
|
||
复制按钮插件的国际化配置。 | ||
|
||
- 示例: | ||
|
||
```ts | ||
import { copyCodePlugin } from "vuepress-plugin-copy-code2"; | ||
|
||
export default { | ||
locales: { | ||
"/": { | ||
// 这是一个支持的语言 | ||
lang: "zh-CN", | ||
}, | ||
"/xx/": { | ||
// 这是一个没有收到插件支持的语言 | ||
lang: "mm-NN", | ||
}, | ||
}, | ||
|
||
plugins: [ | ||
copyCodePlugin({ | ||
locales: { | ||
"/": { | ||
// 覆盖复制按钮标签文字 | ||
copy: "复制此段代码", | ||
}, | ||
|
||
"/xx/": { | ||
// 在这里完整设置 `mm-NN` 的多语言配置 | ||
}, | ||
}, | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
::: details 内置支持语言 | ||
|
||
- **简体中文** (zh-CN) | ||
- **繁体中文** (zh-TW) | ||
- **英文(美国)** (en-US) | ||
- **德语** (de-DE) | ||
- **德语(澳大利亚)** (de-AT) | ||
- **俄语** (ru-RU) | ||
- **乌克兰语** (uk-UA) | ||
- **越南语** (vi-VN) | ||
- **葡萄牙语(巴西)** (pt-BR) | ||
- **波兰语** (pl-PL) | ||
- **法语** (fr-FR) | ||
- **西班牙语** (es-ES) | ||
- **斯洛伐克** (sk-SK) | ||
- **日语** (ja-JP) | ||
- **土耳其语** (tr-TR) | ||
- **韩语** (ko-KR) | ||
- **芬兰语** (fi-FI) | ||
- **印尼语** (id-ID) | ||
- **荷兰语** (nl-NL) | ||
|
||
::: | ||
|
||
|
||
## 样式 | ||
|
||
你可以通过 CSS 变量来自定义*复制按钮*的样式: | ||
|
||
|
||
@[code css](@vuepress/plugin-copy-code/src/client/styles/vars.css) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
describe('copy-code', () => { | ||
it('have copy code button', () => { | ||
cy.visit('/markdown.html') | ||
.get('.copy-code-button') | ||
.then((el) => { | ||
expect(el.length).to.be.greaterThan(0) | ||
|
||
cy.wrap(el).click({ multiple: true }) | ||
cy.wrap(el).should('have.class', 'copied') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.