Skip to content
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

feat($theme-default): markdown details custom block (close #768) #2044

Merged
merged 2 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions packages/@vuepress/theme-default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ module.exports = (options, ctx) => {
'/zh/': '警告'
}
}],
['container', {
type: 'details',
before: info => `<details class="custom-block details">${info ? `<summary>${info}</summary>` : ''}\n`,
after: () => '</details>\n'
}],
['smooth-scroll', enableSmoothScroll]
]
}
Expand Down
18 changes: 16 additions & 2 deletions packages/@vuepress/theme-default/styles/custom-blocks.styl
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@
color darken(red, 40%)
a
color $textColor


&.details
display block
position relative
border-radius 2px
margin 1.6em 0
padding 1.6em
background-color #eee
h4
margin-top 0
figure, p
&:last-child
margin-bottom 0
padding-bottom 0
summary
outline none
cursor pointer
24 changes: 22 additions & 2 deletions packages/docs/docs/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Rendering of TOC can be configured using the [`markdown.toc`](../config/README.m

**Input**

```
```md
::: tip
This is a tip
:::
Expand All @@ -135,6 +135,10 @@ This is a warning
::: danger
This is a dangerous warning
:::

::: details
This is a details block, which does not work in IE / Edge
:::
```

**Output**
Expand All @@ -151,18 +155,34 @@ This is a warning
This is a dangerous warning
:::

::: details
This is a details block, which does not work in IE / Edge
:::

You can also customize the title of the block:

```
````md
::: danger STOP
Danger zone, do not proceed
:::

::: details Click me to view the code
```js
console.log('Hello, VuePress!')
```
:::
````

::: danger STOP
Danger zone, do not proceed
:::

::: details Click me to view the code
```js
console.log('Hello, VuePress!')
```
:::

**Also see:**

- [vuepress-plugin-container](https://vuepress.github.io/plugins/container/)
Expand Down
40 changes: 30 additions & 10 deletions packages/docs/docs/zh/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,64 @@ lang: en-US

**输入**

```
```md
::: tip
This is a tip
这是一个提示
:::

::: warning
This is a warning
这是一个警告
:::

::: danger
This is a dangerous warning
这是一个危险警告
:::

::: details
这是一个详情块,在 IE / Edge 中不生效
:::
```

**输出**

::: tip
This is a tip
这是一个提示
:::

::: warning
This is a warning
这是一个警告
:::

::: danger
This is a dangerous thing
这是一个危险警告
:::

::: details
这是一个详情块,在 IE / Edge 中不生效
:::

你也可以自定义块中的标题:

```
````md
::: danger STOP
Danger zone, do not proceed
危险区域,禁止通行
:::

::: details 点击查看代码
```js
console.log('你好,VuePress!')
```
:::
````

::: danger STOP
Danger zone, do not proceed
危险区域,禁止通行
:::

::: details 点击查看代码
```js
console.log('你好,VuePress!')
```
:::

**参考:**
Expand Down