Skip to content

docs: add in CodeGroup and CodeBlock usage docs #2621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions packages/docs/docs/theme/default-theme-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,90 @@ layout: SpecialLayout

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

## Code Groups and Code Blocks <Badge text="1.6.0+" />
The default theme comes with custom components `<code-group />` and `<code-block>` that can help you to better group
separate code paths that have the same result.

**Example**

Yarn and npm installation instructions

**Input**
````md
<code-group>
<code-block title="YARN">
```bash
yarn create vuepress-site [optionalDirectoryName]
```
</code-block>

<code-block title="NPM">
```bash
npx create-vuepress-site [optionalDirectoryName]
```
</code-block>
</code-group>
````

**Output**

<code-group>
<code-block title="YARN">
```bash
yarn create vuepress-site [optionalDirectoryName]
```
</code-block>

<code-block title="NPM">
```bash
npx create-vuepress-site [optionalDirectoryName]
```
</code-block>
</code-group>

::: tip
Each `<code-block />` must have a line break after it to render properly
:::

### Default Code Block

By default, `<code-group />` will use the first `<code-block />` as the active initial code block.

To manually set the active `<code-block />`, just add the `active` prop to the `<code-block />`:

**Input**
````md
<code-group>
<code-block title="YARN">
```bash
yarn create vuepress-site [optionalDirectoryName]
```
</code-block>

<code-block title="NPM" active>
```bash
npx create-vuepress-site [optionalDirectoryName]
```
</code-block>
</code-group>
````

**Output**

<code-group>
<code-block title="YARN">
```bash
yarn create vuepress-site [optionalDirectoryName]
```
</code-block>

<code-block title="NPM" active>
```bash
npx create-vuepress-site [optionalDirectoryName]
```
</code-block>
</code-group>

## Ejecting

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`.
Expand Down