Skip to content

Commit 4bde115

Browse files
committed
more docs
1 parent e242f59 commit 4bde115

File tree

11 files changed

+191
-73
lines changed

11 files changed

+191
-73
lines changed

docs/kitchen/sink.md

-49
This file was deleted.

docs/markdown.md

+88-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,100 @@
11
# Markdown Extensions
22

3-
[[toc]]
4-
53
## Links
64

5+
- Inbound links ending in `.md` or `.html` are converted to `<router-link>` for SPA navigation.
6+
7+
- [Home](/)
8+
- [Setup](./setup.md#quickstart)
9+
10+
- Outbound links automatically gets `target="_blank"`: [vuejs.org](https://vuejs.org)
11+
712
## Header Anchors
813

14+
Headers automatically get anchor links applied.
15+
916
## Table of Contents
1017

18+
**Input**
19+
20+
``` markdown
21+
[[toc]]
22+
```
23+
24+
**Output**
25+
26+
[[toc]]
27+
1128
## Custom Containers
1229

13-
## Configuration
30+
**Input**
31+
32+
``` markdown
33+
::: tip
34+
This is a tip
35+
:::
36+
37+
::: warning
38+
This is a warning
39+
:::
40+
41+
::: danger
42+
This is a dangerous thing
43+
:::
44+
```
45+
46+
**Output**
47+
48+
::: tip
49+
This is a tip
50+
:::
51+
52+
::: warning
53+
This is a warning
54+
:::
55+
56+
::: danger
57+
This is a dangerous thing
58+
:::
59+
60+
## Line Highlighting in Code Blocks
61+
62+
**Input**
63+
64+
```` markdown
65+
``` js{4}
66+
export default {
67+
data () {
68+
return {
69+
msg: 'Highlighted!'
70+
}
71+
}
72+
}
73+
```
74+
````
75+
76+
**Output**
77+
78+
``` js{4}
79+
export default {
80+
data () {
81+
return {
82+
msg: 'Highlighted!'
83+
}
84+
}
85+
}
86+
```
87+
88+
## Emoji
89+
90+
**Input**
91+
92+
``` markdown
93+
:tada: :100:
94+
```
95+
96+
**Output**
1497

15-
## Syntax Highlighting
98+
:tada: :100:
1699

17-
Highlight lines
100+
## Custom Configuration

docs/test.md

-5
This file was deleted.

docs/using-vue.md

+51-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,57 @@
22

33
## Templating
44

5+
Each markdown file is first compiled into HTML and then passed on as a Vue component to `vue-loader`. This means you can use Vue-style interpolation in text:
6+
7+
**Input**
8+
9+
``` markdown
10+
{{ 1 + 1 }}
11+
```
12+
13+
**Output**
14+
15+
<pre><code>{{ 1 + 1 }}</code></pre>
16+
17+
Directives also work:
18+
19+
**Input**
20+
21+
``` markdown
22+
<span v-for="i in 3">{{ i }} </span>
23+
```
24+
25+
**Output**
26+
27+
<pre><code><span v-for="i in 3">{{ i }} </span></code></pre>
28+
29+
The compiled component does not have any private data but do have access to the [site metadata](./theming.md#site-and-page-metadata). For example:
30+
31+
**Input**
32+
33+
``` markdown
34+
{{ $page }}
35+
```
36+
37+
**Output**
38+
39+
<pre><code>{{ $page }}</code></pre>
40+
41+
## Escaping
42+
43+
By default, fenced code blocks are automatically wrapped with `v-pre`. If you want to display raw mustaches or Vue-specific syntax inside inline code snippets or plain text, you need to wrap a paragraph with the `v-pre` custom container:
44+
45+
``` markdown
46+
::: v-pre
47+
`{{ This will be displayed as-is }}`
48+
:::
49+
```
50+
551
## Using Components
652

753
Any `*.vue` file found in `.vuepress/components` are automatically registered as global async components. For example:
854

9-
``` bash
55+
```
1056
.
1157
└── .vuepress
1258
   └── components
@@ -22,9 +68,11 @@ Inside any markdown file you can then use the component like so:
2268
```
2369

2470
::: warning
25-
Note **components must be nested inside a `<div>`**, because otherwise they'd be automatically wrapped inside a `<p>`, which can only contain inline elements.
71+
Note **components must be nested inside a `<div>`**, because otherwise they'd be automatically wrapped inside a `<p>`, which can only contain inline elements. If your component contains block level elements (it mostly likely does), it will cause hydration mismatch in static builds.
2672
:::
2773

28-
## Style & Script
74+
## Script & Style Hoisting
2975

3076
(TODO)
77+
78+
Sometimes you may need to apply some JavaScript or CSS only to the current page. In those case you can directly write root-level `<script>` or `<style>` blocks in the markdown file, and they will be hoisted out of the compiled HTML and used as the `<script>` and `<style>` blocks for the resulting Vue single-file component.

lib/default-theme/styles.css

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pre, pre[class*="language-"] {
77
color: white;
88
line-height: 1.4;
99
border-radius: 5px;
10-
padding: 1.25rem 1.575rem;
10+
padding: 1.3rem 1.575rem;
1111
white-space: pre-wrap;
1212
word-break: break-word;
1313
overflow: auto;
@@ -23,13 +23,23 @@ pre code, pre[class*="language-"] code {
2323
background-color: #14161a;
2424
display: block;
2525
margin: 0 -1.575rem;
26-
padding: 0 1.575rem;
26+
padding: 0.2rem 1.575rem 0;
27+
}
28+
29+
div.tip {
30+
color: white;
31+
background-color: green;
2732
}
2833

2934
div.warning {
3035
background-color: yellow;
3136
}
3237

38+
div.danger {
39+
color: white;
40+
background-color: red;
41+
}
42+
3343
/*
3444
Copied from nprogress since it doens't
3545
allow programmatic configuration of color

lib/dev.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
2323
ignored: '.vuepress/**/*.md',
2424
ignoreInitial: true
2525
})
26-
pagesWatcher.on('add', () => prepare(sourceDir))
27-
pagesWatcher.on('unlink', () => prepare(sourceDir))
26+
const update = () => prepare(sourceDir)
27+
pagesWatcher.on('add', update)
28+
pagesWatcher.on('unlink', update)
29+
pagesWatcher.on('addDir', update)
30+
pagesWatcher.on('unlinkDir', update)
2831

2932
// resolve webpack config
3033
const _config = createClientConfig(options)

lib/markdown/highlight.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1+
const chalk = require('chalk')
12
const prism = require('prismjs')
23
const loadLanguages = require('prismjs/components/index')
34

45
// required to make embedded highlighting work...
56
loadLanguages(['markup', 'css', 'javascript'])
67

8+
function wrap (code, lang) {
9+
return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
10+
}
11+
712
module.exports = (str, lang) => {
13+
if (!lang) {
14+
return wrap(str, 'text')
15+
}
816
if (lang === 'vue' || lang === 'html') {
917
lang = 'markup'
1018
}
1119
if (!prism.languages[lang]) {
1220
try {
1321
loadLanguages([lang])
1422
} catch (e) {
15-
throw new Error(`[vuepress] Syntax highlight for language "${lang}" is not supported.`)
23+
console.log(chalk.yellow(`[vuepress] Syntax highlight for language "${lang}" is not supported.`))
1624
}
1725
}
1826
if (prism.languages[lang]) {
19-
const res = prism.highlight(str, prism.languages[lang], lang)
20-
return `<pre v-pre class="language-${lang}"><code>${res}</code></pre>`
27+
const code = prism.highlight(str, prism.languages[lang], lang)
28+
return wrap(code, lang)
2129
}
22-
return ''
30+
return wrap(str, 'text')
2331
}

lib/markdown/index.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const highlight = require('./highlight')
22
const highlightLines = require('./highlightLines')
33
const convertRouterLink = require('./link')
4+
const emoji = require('markdown-it-emoji')
45
const anchor = require('markdown-it-anchor')
56
const container = require('markdown-it-container')
67
const toc = require('markdown-it-table-of-contents')
@@ -10,16 +11,28 @@ const toc = require('markdown-it-table-of-contents')
1011
// TODO support inline demo
1112

1213
module.exports = ({ markdown = {}}) => {
13-
return require('markdown-it')({
14+
const md = require('markdown-it')({
1415
html: true,
1516
typographer: true,
1617
highlight
1718
})
1819
.use(convertRouterLink)
1920
.use(highlightLines)
21+
.use(emoji)
2022
.use(anchor, Object.assign({ permalink: true, permalinkBefore: true }, markdown.anchor))
2123
.use(toc, Object.assign({ includeLevel: [2, 3] }, markdown.toc))
2224
.use(container, 'tip')
2325
.use(container, 'warning')
2426
.use(container, 'danger')
27+
.use(container, 'v-pre', {
28+
render: (tokens, idx) => tokens[idx].nesting === 1
29+
? `<div v-pre>\n`
30+
: `</div>\n`
31+
})
32+
33+
if (markdown.config) {
34+
markdown.config(md)
35+
}
36+
37+
return md
2538
}

lib/markdown/link.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = md => {
1212
const link = token.attrs[hrefIndex]
1313
const href = link[1]
1414
const isExternal = /^https?:/.test(href)
15-
const isSourceLink = /\.(md|html)$/.test(href)
15+
const isSourceLink = /\.(md|html)(#[\w-]*)?$/.test(href)
1616
if (isExternal) {
1717
const targetIndex = token.attrIndex('target')
1818
if (targetIndex < 0) {
@@ -30,7 +30,9 @@ module.exports = md => {
3030

3131
function toRouterLink (token, link) {
3232
link[0] = 'to'
33-
let to = link[1].replace(/\.md$/, '.html')
33+
let to = link[1]
34+
.replace(/\.md$/, '.html')
35+
.replace(/\.md(#[\w-]*)/, '.html$1')
3436
// normalize links to README/index
3537
if (/^index|readme\.html/i.test(to)) {
3638
to = '/'

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"markdown-it": "^8.4.1",
6060
"markdown-it-anchor": "^4.0.0",
6161
"markdown-it-container": "^2.0.0",
62+
"markdown-it-emoji": "^1.4.0",
6263
"markdown-it-table-of-contents": "^0.3.3",
6364
"mini-css-extract-plugin": "^0.4.0",
6465
"mkdirp": "^0.5.1",

yarn.lock

+4
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,10 @@ markdown-it-container@^2.0.0:
34173417
version "2.0.0"
34183418
resolved "https://registry.yarnpkg.com/markdown-it-container/-/markdown-it-container-2.0.0.tgz#0019b43fd02eefece2f1960a2895fba81a404695"
34193419

3420+
markdown-it-emoji@^1.4.0:
3421+
version "1.4.0"
3422+
resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"
3423+
34203424
markdown-it-table-of-contents@^0.3.3:
34213425
version "0.3.3"
34223426
resolved "https://registry.yarnpkg.com/markdown-it-table-of-contents/-/markdown-it-table-of-contents-0.3.3.tgz#b62e943c32de2c4a27d3e7c83cd63acbc2a9c4a2"

0 commit comments

Comments
 (0)