fix: can't render toc on first load

This commit is contained in:
qingwei.li 2017-05-31 20:42:29 +08:00
parent 91b66a5cac
commit d9b487e67b
No known key found for this signature in database
GPG Key ID: B6DDC2F7AE80B2F4

View File

@ -44,7 +44,8 @@ export class Compiler {
_initRenderer () {
const renderer = new marked.Renderer()
const { linkTarget, router, toc, contentBase } = this
const { linkTarget, router, contentBase } = this
const _self = this
/**
* render anchor tag
* @link https://github.com/chjj/marked#overriding-renderer-methods
@ -67,7 +68,7 @@ export class Compiler {
const slug = slugify(text)
const url = router.toURL(router.getCurrentPath(), { id: slug })
nextToc.slug = url
toc.push(nextToc)
_self.toc.push(nextToc)
return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${text}</span></a></h${level}>`
}