|
1 |
| -# `vuepress-plugin-code-switcher` |
| 1 | +# vuepress-plugin-code-switcher |
| 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. |
2 | 3 |
|
3 |
| -### Installation |
4 |
| -Install `vuepress-plugin-code-switcher` as a dependency and add it to your config's plugin list: |
| 4 | +## Demo |
| 5 | + |
| 6 | + |
| 7 | +## Installation |
| 8 | +``` |
| 9 | +$ npm install vuepress-plugin-code-switcher --save |
| 10 | +``` |
| 11 | + |
| 12 | +After installing, add it to your Vuepress configuration's plugin list: |
5 | 13 |
|
6 | 14 | ```js
|
7 | 15 | module.exports = {
|
8 | 16 | plugins: [ 'code-switcher' ]
|
9 | 17 | }
|
10 | 18 | ```
|
11 | 19 |
|
12 |
| -### Example |
13 |
| -```markdown |
| 20 | +### Usage |
| 21 | +````markdown |
14 | 22 | <CodeSwitcher :languages="{js:'JavaScript',ts:'TypeScript'}">
|
15 | 23 | <template v-slot:js>
|
16 | 24 |
|
17 |
| - ```js |
18 |
| - module.exports = function (str) { |
19 |
| - return typeof str === 'string' && str.trim() === str |
20 |
| - } |
21 |
| - ``` |
| 25 | +```js |
| 26 | +module.exports = function (str) { |
| 27 | + return typeof str === 'string' && str.trim() === str |
| 28 | +} |
| 29 | +``` |
22 | 30 |
|
23 | 31 | </template>
|
24 | 32 | <template v-slot:ts>
|
25 | 33 |
|
26 |
| - ```ts |
27 |
| - export default function isString (str: string) : str is string { |
28 |
| - return typeof str === 'string' && str.trim() === str |
29 |
| - } |
30 |
| - ``` |
| 34 | +```ts |
| 35 | +export default function isString (str: string) : str is string { |
| 36 | + return typeof str === 'string' && str.trim() === str |
| 37 | +} |
| 38 | +``` |
31 | 39 |
|
32 | 40 | </template>
|
33 | 41 | </CodeSwitcher>
|
34 |
| -``` |
| 42 | +```` |
| 43 | + |
| 44 | +> The extra newline between the `<template>` tags and their content is necessary if you want to have Markdown interpreted within the component. |
35 | 45 |
|
36 |
| -The extra newline between the `<template>` tags and their content is necessary if you want to have Markdown interpreted within the component. |
| 46 | +#### Props |
| 47 | +| Prop | Description | Type | Default | |
| 48 | +| ----- | ----- | ---- | ---- | |
| 49 | +| languages | The languages that can be switched between. The object expects shorthands as keys and the tab title as values. The shorthands will also be used as slot names | Object | --- | |
| 50 | +| name | All code switchers on one page with the same name will be synchronized | String | `'default'` | |
| 51 | +| isolated | if true, this block will not synchronize with any others or load/save its state to/from localstorage | Boolean | `false` | |
0 commit comments