-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
data: { | ||
title: 'VuePress' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const prism = require('prismjs') | ||
const loadLanguages = require('prismjs/components/index') | ||
|
||
module.exports = (str, lang) => { | ||
if (lang === 'vue') { | ||
lang = 'html' | ||
} | ||
if (!prism.languages[lang]) { | ||
try { | ||
loadLanguages([lang]) | ||
} catch (e) { | ||
throw new Error(`[vuepress] Syntax highlight for language "${lang}" is not supported.`) | ||
return '' | ||
} | ||
} | ||
if (prism.languages[lang]) { | ||
let res = prism.highlight(str, prism.languages[lang], lang) | ||
return `<pre class="language-${lang}"><code v-pre>${res}</code></pre>` | ||
} | ||
return '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const highlight = require('./highlight') | ||
const convertRouterLink = require('./link') | ||
const container = require('markdown-it-container') | ||
|
||
// TODO extract <style> blocks and <script> blocks | ||
// TODO support inline demo | ||
|
||
module.exports = require('markdown-it')({ | ||
html: true, | ||
typographer: true, | ||
highlight | ||
}) | ||
.use(convertRouterLink) | ||
.use(container, 'tip') | ||
.use(container, 'warning') | ||
.use(container, 'danger') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = md => { | ||
let hasOpenLink = false | ||
|
||
md.renderer.rules.link_open = (tokens, idx, options, env, self) => { | ||
const token = tokens[idx] | ||
const hrefIndex = token.attrIndex('href') | ||
if (hrefIndex >= 0) { | ||
const link = token.attrs[hrefIndex] | ||
const href = link[1] | ||
if (!/^https?:/.test(href) && /\.(md|html)$/.test(href)) { | ||
hasOpenLink = true | ||
tokens[idx] = toRouterLink(token, link) | ||
} | ||
} | ||
return self.renderToken(tokens, idx, options) | ||
} | ||
|
||
function toRouterLink (token, link) { | ||
link[0] = 'to' | ||
link[1] = link[1].replace(/\.md$/, '.html') | ||
return Object.assign({}, token, { | ||
tag: 'router-link' | ||
}) | ||
} | ||
|
||
md.renderer.rules.link_close = (tokens, idx, options, env, self) => { | ||
const token = tokens[idx] | ||
if (hasOpenLink) { | ||
token.tag = 'router-link' | ||
hasOpenLink = false | ||
} | ||
return self.renderToken(tokens, idx, options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters