|
1 | 1 | # vuepress-plugin-code-switcher |
2 | 2 | Component that allows having synchronized language switchable code blocks (e.g. to switch between Java and Kotlin examples). Selected languages are persisted to local storage to have language selection be permanent across page requests. |
3 | 3 |
|
4 | | -_Requires Vuepress 1.0+_ |
| 4 | +This plugin supports both Vuepress 1 and 2. Since Vuepress 1 plugins are incompatible with Vuepress 2 I try to maintain the plugin for both Vuepress versions. Those plugin versions can be seen in different GitHub branches as shown below. |
| 5 | + |
| 6 | +| | Vuepress 1 | Vuepress 2 | |
| 7 | +| -- | --- | --- | |
| 8 | +| npm | Versions `1.x.x` | Versions `2.x.x` | |
| 9 | +| GitHub | [`vuepress-1` Branch](https://github.com/padarom/vuepress-plugin-code-switcher/tree/vuepress-1) | [`main` Branch](https://github.com/padarom/vuepress-plugin-code-switcher/tree/main) | |
5 | 10 |
|
6 | 11 | ## Demo |
7 | 12 | A live demo is available at https://code-switcher.padarom.xyz. |
8 | 13 |
|
9 | 14 |  |
10 | 15 | ## Installation |
| 16 | +**These instructions are only valid for Vuepress 2. If you use Vuepress 1, see [here](https://github.com/padarom/vuepress-plugin-code-switcher/blob/vuepress-1/README.md#installation).** |
| 17 | + |
11 | 18 | ``` |
12 | | -$ npm install vuepress-plugin-code-switcher --save |
| 19 | +$ npm install vuepress-plugin-code-switcher@~2.0 --save |
13 | 20 | ``` |
14 | 21 |
|
15 | 22 | After installing, add it to your Vuepress configuration's plugin list: |
16 | 23 |
|
17 | | -```js |
18 | | -module.exports = { |
| 24 | +```ts |
| 25 | +import { codeSwitcherPlugin } from 'vuepress-plugin-code-switcher' |
| 26 | + |
| 27 | +export default { |
19 | 28 | // Your remaining configuration ... |
20 | | - plugins: [ 'code-switcher' ], |
| 29 | + plugins: [ codeSwitcherPlugins(/* your config options go here */) ], |
21 | 30 | } |
22 | 31 | ``` |
23 | 32 |
|
@@ -53,18 +62,22 @@ specify your languages every single time. Therefore you can instantiate the |
53 | 62 | plugin with options and name the default languages for a given group: |
54 | 63 |
|
55 | 64 | ```js |
56 | | -module.exports = { |
| 65 | +import { codeSwitcherPlugin } from 'vuepress-plugin-code-switcher' |
| 66 | + |
| 67 | +export default { |
57 | 68 | // Your remaining configuration ... |
58 | 69 | plugins: [ |
59 | | - [ |
60 | | - 'code-switcher', |
61 | | - { |
62 | | - groups: { |
63 | | - default: { ts: 'TypeScript', js: 'JavaScript' }, |
64 | | - jvm: { java: 'Java', kotlin: 'Kotlin', jruby: 'JRuby' }, |
65 | | - }, |
| 70 | + codeSwitcherPlugins({ |
| 71 | + groups: { |
| 72 | + default: { ts: 'TypeScript', js: 'JavaScript' }, |
| 73 | + jvm: { java: 'Java', kotlin: 'Kotlin', jruby: 'JRuby' }, |
66 | 74 | }, |
67 | | - ], |
| 75 | + |
| 76 | + // You can also specify a custom name for the code switcher component. |
| 77 | + // If chaning the name like so, you then use the component as <CustomCodeSwitcher> |
| 78 | + // in your markdown code |
| 79 | + componentName: 'CustomCodeSwitcher', |
| 80 | + }) |
68 | 81 | ], |
69 | 82 | } |
70 | 83 | ``` |
|
0 commit comments