Skip to content

Commit f1b2830

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

8 files changed

Lines changed: 152 additions & 38 deletions

File tree

docs/markdown/advance/4-highlight.md

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 高亮
1+
# 代码高亮
22

33
## 代码块中的语法高亮
44

@@ -29,11 +29,14 @@ export default {
2929
````
3030
``` html
3131
<ul>
32-
<li
33-
v-for="todo in todos"
34-
:key="todo.id"
35-
>
36-
{{ todo.text }}
32+
<li>
33+
a
34+
</li>
35+
<li>
36+
bb
37+
</li>
38+
<li>
39+
ccc
3740
</li>
3841
</ul>
3942
```
@@ -43,11 +46,14 @@ export default {
4346

4447
``` html
4548
<ul>
46-
<li
47-
v-for="todo in todos"
48-
:key="todo.id"
49-
>
50-
{{ todo.text }}
49+
<li>
50+
a
51+
</li>
52+
<li>
53+
bb
54+
</li>
55+
<li>
56+
ccc
5157
</li>
5258
</ul>
5359
```
@@ -139,30 +145,4 @@ module.exports = {
139145

140146
- 示例:
141147

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>
148+
![示例](./images/2021-10-26-21-54-27.png)

docs/markdown/advance/5-import.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# 导入代码段
2+
3+
::: tip 注意
4+
由于代码段的导入将在 webpack 编译之前执行,因此你无法使用 webpack 中的路径别名,默认基于文档更目录开始。
5+
:::
6+
7+
8+
你可以通过下述的语法导入已经存在的文件中的代码段:
9+
10+
``` md
11+
<<< ./filepath
12+
```
13+
14+
它也支持 [行高亮](./4-highlight.md#代码块中的行高亮)
15+
16+
``` md
17+
<<< ./filepath{highlightLines}
18+
```
19+
20+
**输入**
21+
22+
```
23+
<<< ./markdown/advance/fragments/snippet.js{2}
24+
```
25+
26+
**输出**
27+
28+
<<< ./markdown/advance/fragments/snippet.js{2}
29+
30+
31+
为了只导入对应部分的代码,你也可运用 [VS Code region](https://code.visualstudio.com/docs/editor/codebasics#_folding)。你可以在文件路径后方的 `#` 紧接着提供一个自定义的区域名称(预设为 `snippet`
32+
33+
**输入**
34+
35+
``` md
36+
<<< ./markdown/advance/fragments/snippet-with-region.js#snippet{1}
37+
```
38+
39+
**代码文件**
40+
41+
<<< ./markdown/advance/fragments/snippet-with-region.js
42+
43+
**输出**
44+
45+
<<< ./markdown/advance/fragments/snippet-with-region.js#snippet{1}

docs/markdown/advance/6-include.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 导入文本
2+
3+
::: tip 注意
4+
由于代码段的导入将在 webpack 编译之前执行,因此你无法使用 webpack 中的路径别名,默认基于文档更目录开始。
5+
:::
6+
7+
::: warning 注意
8+
由于导入是全局性质的,以下内容中`<<<``include` 之间的空格,使用时需要删除
9+
:::
10+
11+
你可以通过下述的语法导入已经存在的文件文本:
12+
13+
``` md
14+
<<< include(@/filepath)
15+
```
16+
17+
或者
18+
19+
``` md
20+
<<< include @/filepath
21+
```
22+
23+
**输入**
24+
25+
```
26+
<<< include(./markdown/advance/fragments/snippet.js)
27+
```
28+
29+
**输出**
30+
31+
<<<include(./markdown/advance/fragments/snippet.js)
32+
33+
34+
为了只导入对应部分的代码,你也可运用 [VS Code region](https://code.visualstudio.com/docs/editor/codebasics#_folding)。你可以在文件路径后方的 `#` 紧接着提供一个自定义的区域名称(预设为 `snippet`
35+
36+
**输入**
37+
38+
``` md
39+
<<< include(./markdown/advance/fragments/snippet-with-region.js#snippet)
40+
```
41+
42+
**代码文件**
43+
44+
<<< ./markdown/advance/fragments/snippet-with-region.js
45+
46+
**输出**
47+
48+
<<<include(./markdown/advance/fragments/snippet-with-region.js#snippet)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Fragments
2+
3+
code-snippet-with-region.md
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// #region snippet
2+
function foo () {
3+
return ({
4+
dest: '../../vuepress',
5+
locales: {
6+
'/': {
7+
lang: 'en-US',
8+
title: 'VuePress',
9+
description: 'Vue-powered Static Site Generator'
10+
},
11+
'/zh/': {
12+
lang: 'zh-CN',
13+
title: 'VuePress',
14+
description: 'Vue 驱动的静态网站生成器'
15+
}
16+
},
17+
head: [
18+
['link', { rel: 'icon', href: `/logo.png` }],
19+
['link', { rel: 'manifest', href: '/manifest.json' }],
20+
['meta', { name: 'theme-color', content: '#3eaf7c' }],
21+
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
22+
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
23+
['link', { rel: 'apple-touch-icon', href: `/icons/apple-touch-icon-152x152.png` }],
24+
['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
25+
['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],
26+
['meta', { name: 'msapplication-TileColor', content: '#000000' }]
27+
]
28+
})
29+
}
30+
// #endregion snippet
31+
32+
export default foo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function () {
2+
// ..
3+
}
118 KB
Loading

microapp/vuepress.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function getMarkdownSidebar() {
170170
children: [
171171
'',
172172
...require('fs-extra').readdirSync(require('path').resolve(__dirname, '../docs/markdown/basic'))
173+
.filter(name => /\.md$/ig.test(name))
173174
.sort((a, b) => parseInt(a) - parseInt(b))
174175
.map(name => `basic/${name}`),
175176
],
@@ -179,6 +180,8 @@ function getMarkdownSidebar() {
179180
collapsable: false,
180181
children: [
181182
...require('fs-extra').readdirSync(require('path').resolve(__dirname, '../docs/markdown/advance'))
183+
.filter(name => /\.md$/ig.test(name))
184+
.sort((a, b) => parseInt(a) - parseInt(b))
182185
.map(name => `advance/${name}`),
183186
],
184187
},

0 commit comments

Comments
 (0)