Skip to content

Commit 2e6288a

Browse files
committed
fix md render
1 parent 859dc19 commit 2e6288a

File tree

7 files changed

+43
-8
lines changed

7 files changed

+43
-8
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"less-loader": "^4.0.5",
100100
"less-plugin-npm-import": "^2.1.0",
101101
"markdown-it": "^8.4.0",
102+
"markdown-it-anchor": "^4.0.0",
102103
"marked": "^0.3.7",
103104
"merge2": "^1.2.1",
104105
"mkdirp": "^0.5.1",

site/components/api.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class='markdown api-container' id="component-api">
2+
<div class='markdown api-container'>
33
<slot v-if="isZhCN" name="cn"></slot>
44
<slot v-else></slot>
55
</div>

site/components/demo.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export default {
4848
{lis}
4949
<li title='API' key='API'>
5050
<a
51-
href='#component-api'
51+
href='#api'
5252
class={{
53-
current: window.location.hash === '#component-api',
53+
current: window.location.hash === '#api',
5454
}}
5555
>API</a>
5656
</li>

site/components/demoBox.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ export default {
5353
`not have usTitle`,
5454
)
5555
}
56-
const component = this.$slots.component[0]
57-
const fileName = (component.context.$vnode.componentOptions.Ctor.extendOptions.__file.split('/demo/')[1] || '').replace('.md', '')
58-
const id = ['components', name.replace('-cn', ''), 'demo', fileName].join('-').toLowerCase()
59-
console.log(fileName)
56+
let id = ['components', name.replace('-cn', ''), 'demo', ...usTitle.split(' ')].join('-').toLowerCase()
57+
6058
if (this._store.store) {
6159
const { currentSubMenu } = this._store.store.getState()
60+
id = `${id}-${currentSubMenu.length + 1}`
6261
this._store.store.setState({ currentSubMenu: [...currentSubMenu, { cnTitle, usTitle, id }] })
6362
}
6463
return {

site/components/md.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@
44
<script>
55
import marked from 'marked'
66
import { isZhCN } from '../util'
7+
var renderer = new marked.Renderer();
8+
renderer.heading = function(text, level) {
9+
return '<h'
10+
+ level
11+
+ ' id="'
12+
+ text.replace(/[^\w]+/g, '-')
13+
+ '">'
14+
+ text
15+
+ '</h'
16+
+ level
17+
+ '>\n';
18+
};
719
marked.setOptions({
8-
renderer: new marked.Renderer(),
20+
renderer,
921
gfm: true,
1022
tables: true,
1123
breaks: true,

webpack.base.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ const md = require('markdown-it')('default', {
4545
html: true,
4646
breaks: true,
4747
highlight: renderHighlight,
48+
}).use(require('markdown-it-anchor'), {
49+
level: 2,
50+
// slugify: string => string,
51+
permalink: true,
52+
// renderPermalink: (slug, opts, state, permalink) => {},
53+
permalinkClass: 'anchor',
54+
permalinkSymbol: '#',
55+
permalinkBefore: false,
4856
})
4957
// md.renderer.rules.fence = wrap(md.renderer.rules.fence)
5058
const cnReg = new RegExp('<(cn)(?:[^<]|<)+</\\1>', 'g')

0 commit comments

Comments
 (0)