Skip to content

Commit 9e4e635

Browse files
committed
docs(plugin-container): add plugin reference
1 parent 00fec25 commit 9e4e635

File tree

2 files changed

+274
-2
lines changed

2 files changed

+274
-2
lines changed

docs/reference/plugin/container.md

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,139 @@
11
# container
22

3-
> TODO
3+
> @vuepress/plugin-container
4+
5+
Register markdown custom containers in your VuePress site.
6+
7+
This plugin simplifies the use of [markdown-it-container](https://github.com/markdown-it/markdown-it-container), but also retains its original capabilities.
8+
9+
The [Custom Containers](../default-theme/markdown.md#custom-containers) of default theme is powered by this plugin.
10+
11+
## Container Syntax
12+
13+
```md
14+
::: <type> [info]
15+
[content]
16+
:::
17+
```
18+
19+
- The `type` is required and should be specified via [type](#type) option.
20+
- The `info` is optional, and the default value can be specified via `defaultInfo` in [locales](#locales) option.
21+
- The `content` can be any valid markdown content.
22+
23+
## Options
24+
25+
### type
26+
27+
- Type: `string`
28+
29+
- Details:
30+
31+
The type of the container.
32+
33+
It will be used as the `name` param of [markdown-it-container](https://github.com/markdown-it/markdown-it-container#api).
34+
35+
### locales
36+
37+
- Type: `Record<string, { defaultInfo: string }>`
38+
39+
- Details:
40+
41+
The default `info` of the container in different locales.
42+
43+
If this option is not specified, the default `info` will fallback to the uppercase of the [type](#type) option.
44+
45+
- Example:
46+
47+
```js
48+
module.exports = {
49+
plugins: [
50+
[
51+
'@vuepress/container',
52+
{
53+
type: 'tip',
54+
locales: {
55+
'/': {
56+
defaultInfo: 'TIP',
57+
},
58+
'/zh/': {
59+
defaultInfo: '提示',
60+
},
61+
},
62+
},
63+
],
64+
],
65+
}
66+
```
67+
68+
### before
69+
70+
- Type: `(info: string) => string`
71+
72+
- Default:
73+
74+
```ts
75+
(info: string): string =>
76+
`<div class="custom-container ${type}">${info ? `<p class="custom-container-title">${info}</p>` : ''}\n`
77+
```
78+
79+
- Details:
80+
81+
A function to render the starting tag of the container.
82+
83+
The first param is the `info` part of [container syntax](#container-syntax).
84+
85+
This option will not take effect if you don't specify the [after](#after) option.
86+
87+
### after
88+
89+
- Type: `(info: string) => string`
90+
91+
- Default:
92+
93+
```ts
94+
(): string => '</div>\n'
95+
```
96+
97+
- Details:
98+
99+
A function to render the ending tag of the container.
100+
101+
The first param is the `info` part of [container syntax](#container-syntax).
102+
103+
This option will not take effect if you don't specify the [before](#before) option.
104+
105+
### render
106+
107+
- Type:
108+
109+
```ts
110+
type MarkdownItContainerRenderFunction = (
111+
tokens: Token[],
112+
index: number,
113+
options: any,
114+
env: MarkdownEnv,
115+
self: Renderer
116+
) => string
117+
```
118+
119+
- Details:
120+
121+
The `render` option of [markdown-it-container](https://github.com/markdown-it/markdown-it-container#api).
122+
123+
This plugin uses a default `render` function. If you specify this option, the default `render` function will be replaced, and the [locales](#locales), [before](#before) and [after](#after) options will be ignored.
124+
125+
### validate
126+
127+
- Type: `(params: string) => boolean`
128+
129+
- Details:
130+
131+
The `validate` option of [markdown-it-container](https://github.com/markdown-it/markdown-it-container#api).
132+
133+
### marker
134+
135+
- Type: `string`
136+
137+
- Details:
138+
139+
The `marker` option of [markdown-it-container](https://github.com/markdown-it/markdown-it-container#api).

docs/zh/reference/plugin/container.md

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,139 @@
11
# container
22

3-
> TODO
3+
> @vuepress/plugin-container
4+
5+
为你的 VuePress 站点注册自定义容器。
6+
7+
该插件简化了 [markdown-it-container](https://github.com/markdown-it/markdown-it-container) 的使用方法,但同时也保留了其原本的能力。
8+
9+
默认主题的 [自定义容器](../default-theme/markdown.md#自定义容器) 就是由该插件支持的。
10+
11+
## 容器语法
12+
13+
```md
14+
::: <type> [info]
15+
[content]
16+
:::
17+
```
18+
19+
- `type` 是必需的,应通过 [type](#type) 配置项来指定。
20+
- `info` 是可选的,其默认值可以通过 [locales](#locales)`defaultInfo` 配置项来指定。
21+
- `content` 可是任何合法的 Markdown 内容。
22+
23+
## 配置项
24+
25+
### type
26+
27+
- 类型: `string`
28+
29+
- 详情:
30+
31+
容器的类型。
32+
33+
它将会被用作 [markdown-it-container](https://github.com/markdown-it/markdown-it-container#api)`name` 参数。
34+
35+
### locales
36+
37+
- 类型: `Record<string, { defaultInfo: string }>`
38+
39+
- 详情:
40+
41+
容器在不同 locales 下的默认 `info`
42+
43+
如果没有指定该配置项,默认 `info` 会使用大写的 [type](#type)
44+
45+
- 示例:
46+
47+
```js
48+
module.exports = {
49+
plugins: [
50+
[
51+
'@vuepress/container',
52+
{
53+
type: 'tip',
54+
locales: {
55+
'/': {
56+
defaultInfo: 'TIP',
57+
},
58+
'/zh/': {
59+
defaultInfo: '提示',
60+
},
61+
},
62+
},
63+
],
64+
],
65+
}
66+
```
67+
68+
### before
69+
70+
- 类型: `(info: string) => string`
71+
72+
- 默认值:
73+
74+
```ts
75+
(info: string): string =>
76+
`<div class="custom-container ${type}">${info ? `<p class="custom-container-title">${info}</p>` : ''}\n`
77+
```
78+
79+
- 详情:
80+
81+
一个用于渲染容器起始标签的函数。
82+
83+
第一个参数是 [容器语法](#容器语法)`info` 部分。
84+
85+
如果你没有设置 [after](#after) 配置项,则该配置项也不会生效。
86+
87+
### after
88+
89+
- 类型: `(info: string) => string`
90+
91+
- 默认值:
92+
93+
```ts
94+
(): string => '</div>\n'
95+
```
96+
97+
- 详情:
98+
99+
一个用于渲染容器结束标签的函数。
100+
101+
第一个参数是 [容器语法](#容器语法)`info` 部分。
102+
103+
如果你没有设置 [before](#before) 配置项,则该配置项也不会生效。
104+
105+
### render
106+
107+
- 类型:
108+
109+
```ts
110+
type MarkdownItContainerRenderFunction = (
111+
tokens: Token[],
112+
index: number,
113+
options: any,
114+
env: MarkdownEnv,
115+
self: Renderer
116+
) => string
117+
```
118+
119+
- 详情:
120+
121+
[markdown-it-container](https://github.com/markdown-it/markdown-it-container#api) 的 `render` 配置项。
122+
123+
该插件使用了一个默认的 `render` 函数。但如果你指定了该配置项,那么默认的 `render` 函数就会被替换掉,此时 [locales](#locales) 、 [before](#before) 和 [after](#after) 配置项都会被忽略。
124+
125+
### validate
126+
127+
- 类型: `(params: string) => boolean`
128+
129+
- 详情:
130+
131+
[markdown-it-container](https://github.com/markdown-it/markdown-it-container#api) 的 `validate` 配置项。
132+
133+
### marker
134+
135+
- 类型: `string`
136+
137+
- 详情:
138+
139+
[markdown-it-container](https://github.com/markdown-it/markdown-it-container#api) 的 `marker` 配置项。

0 commit comments

Comments
 (0)