Skip to content

Commit 4a7d3a1

Browse files
committed
docs: add markdown advance
1 parent fbaad23 commit 4a7d3a1

4 files changed

Lines changed: 286 additions & 0 deletions

File tree

docs/markdown/advance/1-link.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 链接
2+
3+
## 内部链接
4+
5+
网站内部的链接,将会被转换成 `<router-link>` 用于 SPA 导航。同时,站内的每一个文件夹下的 `README.md` 或者 `index.md` 文件都会被自动编译为 `index.html`,对应的链接将被视为 `/`
6+
7+
以如下的文件结构为例:
8+
9+
```
10+
.
11+
├─ README.md
12+
├─ foo
13+
│ ├─ README.md
14+
│ ├─ one.md
15+
│ └─ two.md
16+
└─ bar
17+
├─ README.md
18+
├─ three.md
19+
└─ four.md
20+
```
21+
22+
假设你现在在 `foo/one.md` 中:
23+
24+
``` md
25+
[Home](/) <!-- 跳转到根部的 README.md -->
26+
[foo](/foo/) <!-- 跳转到 foo 文件夹的 index.html -->
27+
[foo heading](./#heading) <!-- 跳转到 foo/index.html 的特定标题位置 -->
28+
[bar - three](../bar/three.md) <!-- 具体文件可以使用 .md 结尾(推荐) -->
29+
[bar - four](../bar/four.html) <!-- 也可以用 .html -->
30+
```
31+
32+
## 外部链接
33+
34+
外部的链接将会被自动地设置为 `target="_blank" rel="noopener noreferrer"`:
35+
36+
- [vuejs.org](https://vuejs.org)
37+
- [VuePress on GitHub](https://github.com/vuejs/vuepress)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Front Matter
2+
3+
VuePress 提供了对 [YAML front matter](https://jekyllrb.com/docs/frontmatter/) 开箱即用的支持:
4+
5+
``` yaml
6+
---
7+
title: Blogging Like a Hacker
8+
lang: en-US
9+
---
10+
```
11+
12+
这些数据可以在当前 markdown 的正文,或者是任意的自定义或主题组件中使用。
13+
14+
想了解更多,请移步 [Front Matter](../../guide/deep/frontmatter.md)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# 自定义容器
2+
3+
**输入**
4+
5+
```md
6+
::: tip
7+
这是一个提示
8+
:::
9+
10+
::: warning
11+
这是一个警告
12+
:::
13+
14+
::: danger
15+
这是一个危险警告
16+
:::
17+
18+
::: details
19+
这是一个详情块,在 IE / Edge 中不生效
20+
:::
21+
```
22+
23+
**输出**
24+
25+
::: tip
26+
这是一个提示
27+
:::
28+
29+
::: warning
30+
这是一个警告
31+
:::
32+
33+
::: danger
34+
这是一个危险警告
35+
:::
36+
37+
::: details
38+
这是一个详情块,在 IE / Edge 中不生效
39+
:::
40+
41+
你也可以自定义块中的标题:
42+
43+
````md
44+
::: danger STOP
45+
危险区域,禁止通行
46+
:::
47+
48+
::: details 点击查看代码
49+
```js
50+
console.log('你好,VuePress!')
51+
```
52+
:::
53+
````
54+
55+
::: danger STOP
56+
危险区域,禁止通行
57+
:::
58+
59+
::: details 点击查看代码
60+
```js
61+
console.log('你好,VuePress!')
62+
```
63+
:::
64+
65+
**参考:**
66+
67+
- [vuepress-plugin-container](https://vuepress.github.io/plugins/container/)
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# 高亮
2+
3+
## 代码块中的语法高亮
4+
5+
VuePress 使用了 [Prism](https://prismjs.com/) 来为 markdown 中的代码块实现语法高亮。Prism 支持大量的编程语言,你需要做的只是在代码块的开始倒勾中附加一个有效的语言别名:
6+
7+
**输入**
8+
9+
````
10+
``` js
11+
export default {
12+
name: 'MyComponent',
13+
// ...
14+
}
15+
```
16+
````
17+
18+
**输出**
19+
20+
``` js
21+
export default {
22+
name: 'MyComponent',
23+
// ...
24+
}
25+
```
26+
27+
**输入**
28+
29+
````
30+
``` html
31+
<ul>
32+
<li
33+
v-for="todo in todos"
34+
:key="todo.id"
35+
>
36+
{{ todo.text }}
37+
</li>
38+
</ul>
39+
```
40+
````
41+
42+
**输出**
43+
44+
``` html
45+
<ul>
46+
<li
47+
v-for="todo in todos"
48+
:key="todo.id"
49+
>
50+
{{ todo.text }}
51+
</li>
52+
</ul>
53+
```
54+
55+
在 Prism 的网站上查看 [合法的语言列表](https://prismjs.com/#languages-list)
56+
57+
58+
## 代码块中的行高亮
59+
60+
**输入**
61+
62+
````
63+
``` js {4}
64+
export default {
65+
data () {
66+
return {
67+
msg: 'Highlighted!'
68+
}
69+
}
70+
}
71+
```
72+
````
73+
74+
**输出**
75+
76+
``` js{4}
77+
export default {
78+
data () {
79+
return {
80+
msg: 'Highlighted!'
81+
}
82+
}
83+
}
84+
```
85+
86+
除了单行以外,你也可指定多行,行数区间,或是两者都指定。
87+
88+
- 行数区间: 例如 `{5-8}`, `{3-10}`, `{10-17}`
89+
- 多个单行: 例如 `{4,7,9}`
90+
- 行数区间与多个单行: 例如 `{4,7-13,16,23-27,40}`
91+
92+
**Input**
93+
94+
````
95+
``` js{1,4,6-7}
96+
export default { // Highlighted
97+
data () {
98+
return {
99+
msg: `Highlighted!
100+
This line isn't highlighted,
101+
but this and the next 2 are.`,
102+
motd: 'VuePress is awesome',
103+
lorem: 'ipsum',
104+
}
105+
}
106+
}
107+
```
108+
````
109+
110+
**Output**
111+
112+
``` js{1,4,6-8}
113+
export default { // Highlighted
114+
data () {
115+
return {
116+
msg: `Highlighted!
117+
This line isn't highlighted,
118+
but this and the next 2 are.`,
119+
motd: 'VuePress is awesome',
120+
lorem: 'ipsum',
121+
}
122+
}
123+
}
124+
```
125+
126+
## 行号
127+
128+
你可以通过配置来为每个代码块显示行号:
129+
130+
``` js
131+
module.exports = {
132+
markdown: {
133+
lineNumbers: true
134+
}
135+
}
136+
```
137+
138+
<!-- TODO Support line numbers for specific fence block -->
139+
140+
- 示例:
141+
142+
<picture>
143+
<source srcset="/line-numbers-desktop.png" media="(min-width: 719px)">
144+
<img class="line-numbers-desktop-snap" alt="Image">
145+
</picture>
146+
147+
<picture>
148+
<source srcset="/line-numbers-mobile.gif" media="(max-width: 719px)">
149+
<img class="line-numbers-mobile-snap" alt="Image">
150+
</picture>
151+
152+
<style>
153+
@media screen and (min-width: 719px) {
154+
.line-numbers-mobile-snap {
155+
display: none;
156+
}
157+
}
158+
@media screen and (max-width: 719px) {
159+
.line-numbers-desktop-snap {
160+
display: none;
161+
}
162+
.line-numbers-mobile-snap {
163+
max-width: none!important;
164+
margin: 0 -1.5rem;
165+
width: 100vw;
166+
}
167+
}
168+
</style>

0 commit comments

Comments
 (0)