Skip to content

Commit 12c2beb

Browse files
committed
docs: docuement using components in headers
1 parent 9948172 commit 12c2beb

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs/guide/using-vue.md

+20
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ Inside any markdown file you can then directly use the components (names are inf
126126
Make sure a custom component's name either contains a hyphen or is in PascalCase. Otherwise it will be treated as an inline element and wrapped inside a `<p>` tag, which will lead to hydration mismatch because `<p>` does not allow block elements to be placed inside it.
127127
:::
128128

129+
### Using Components In Headers
130+
131+
You can use Vue components in the headers, but note the difference between the following two ways:
132+
133+
| markdown | Output HTML | Parsed Header |
134+
|--------|-------------|----------------|
135+
| <pre v-pre><code> # text &lt;Tag/&gt; </code></pre> | `<h1>text <Tag/></h1>` | `text` |
136+
| <pre v-pre><code> # text \`&lt;Tag/&gt;\` </code></pre> | `<h1>text <code>&lt;Tag/&gt;</code></h1>` | `text <Tag/>` |
137+
138+
The HTML wrapped by `<code>` will be displayed as is, only the HTML that is not wrapped will be parsed by Vue.
139+
140+
::: tip
141+
142+
The output HTML is accomplish by [markdown-it](https://github.com/markdown-it/markdown-it), while the parsed header is done by VuePress, and used for the [sidebar](../default-theme-config/README.md#sidebar) and the document title.
143+
:::
144+
129145
## Using Pre-processors
130146

131147
VuePress has built-in webpack config for the following pre-processors: `sass`, `scss`, `less`, `stylus` and `pug`. All you need to do is installing the corresponding dependencies. For example, to enable `sass`, install the following in your project:
@@ -220,3 +236,7 @@ You can use this component in header to add some status for some API:
220236
``` md
221237
### Badge <Badge text="beta" type="warn"/> <Badge text="0.10.1+"/>
222238
```
239+
240+
**Also see:**
241+
242+
- [Using Components In Headers](#using-components-in-headers)

docs/zh/guide/using-vue.md

+18
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ export default {
126126
请确保一个自定义组件的名字包含连接符或者是 PascalCase,否则,它将会被视为一个内联元素,并被包裹在一个 `<p>` 标签中,这将会导致 HTML 渲染紊乱,因为 HTML 标准规定, `<p>` 标签中不允许放置任何块级元素。
127127
:::
128128

129+
### 在标题中使用组件
130+
131+
你可以在标题中使用 Vue 组件,但是请留意以下两种方式的不同:
132+
133+
| Markdown | 输出的 HTML | 解析后的标题 |
134+
|--------|-------------|----------------|
135+
| <pre v-pre><code> # text &lt;Tag/&gt; </code></pre> | `<h1>text <Tag/></h1>` | `text` |
136+
| <pre v-pre><code> # text \`&lt;Tag/&gt;\` </code></pre> | `<h1>text <code>&lt;Tag/&gt;</code></h1>` | `text <Tag/>` |
137+
138+
`<code>` 包装的 HTML 将按原样显示,只有未被包装的 HTML 才会被 Vue 解析。
139+
140+
::: tip
141+
输出的 HTML 由 [markdown-it](https://github.com/markdown-it/markdown-it) 完成。而解析后的标题由 VuePress 完成,用于[侧边栏](../default-theme-config/README.md#侧边栏)以及文档的标题。
142+
:::
129143

130144
## 使用预处理器
131145

@@ -223,3 +237,7 @@ export default {
223237
``` md
224238
### Badge <Badge text="beta" type="warn"/> <Badge text="0.10.1+"/>
225239
```
240+
241+
**参考:**
242+
243+
- [在标题中使用组件](#在标题中使用组件)

0 commit comments

Comments
 (0)