Skip to content

Commit 9bc09f8

Browse files
authored
docs: add in CodeGroup and CodeBlock usage docs (#2621)
1 parent 8d10119 commit 9bc09f8

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

packages/docs/docs/theme/default-theme-config.md

+84
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,90 @@ layout: SpecialLayout
557557

558558
This will render `.vuepress/components/SpecialLayout.vue` for the given page.
559559

560+
## Code Groups and Code Blocks <Badge text="1.6.0+" />
561+
The default theme comes with custom components `<code-group />` and `<code-block>` that can help you to better group
562+
separate code paths that have the same result.
563+
564+
**Example**
565+
566+
Yarn and npm installation instructions
567+
568+
**Input**
569+
````md
570+
<code-group>
571+
<code-block title="YARN">
572+
```bash
573+
yarn create vuepress-site [optionalDirectoryName]
574+
```
575+
</code-block>
576+
577+
<code-block title="NPM">
578+
```bash
579+
npx create-vuepress-site [optionalDirectoryName]
580+
```
581+
</code-block>
582+
</code-group>
583+
````
584+
585+
**Output**
586+
587+
<code-group>
588+
<code-block title="YARN">
589+
```bash
590+
yarn create vuepress-site [optionalDirectoryName]
591+
```
592+
</code-block>
593+
594+
<code-block title="NPM">
595+
```bash
596+
npx create-vuepress-site [optionalDirectoryName]
597+
```
598+
</code-block>
599+
</code-group>
600+
601+
::: tip
602+
Each `<code-block />` must have a line break after it to render properly
603+
:::
604+
605+
### Default Code Block
606+
607+
By default, `<code-group />` will use the first `<code-block />` as the active initial code block.
608+
609+
To manually set the active `<code-block />`, just add the `active` prop to the `<code-block />`:
610+
611+
**Input**
612+
````md
613+
<code-group>
614+
<code-block title="YARN">
615+
```bash
616+
yarn create vuepress-site [optionalDirectoryName]
617+
```
618+
</code-block>
619+
620+
<code-block title="NPM" active>
621+
```bash
622+
npx create-vuepress-site [optionalDirectoryName]
623+
```
624+
</code-block>
625+
</code-group>
626+
````
627+
628+
**Output**
629+
630+
<code-group>
631+
<code-block title="YARN">
632+
```bash
633+
yarn create vuepress-site [optionalDirectoryName]
634+
```
635+
</code-block>
636+
637+
<code-block title="NPM" active>
638+
```bash
639+
npx create-vuepress-site [optionalDirectoryName]
640+
```
641+
</code-block>
642+
</code-group>
643+
560644
## Ejecting
561645

562646
You can copy the default theme source code into `.vuepress/theme` to fully customize the theme using the `vuepress eject [targetDir]` command. If you didn’t install VuePress globally, run `./node_modules/.bin/vuepress eject`.

0 commit comments

Comments
 (0)