Ensure autoHeader dom result is similar to parsed H1 (#811)

This commit is contained in:
cyrilf 2020-02-04 18:04:44 +01:00 committed by GitHub
parent b83622e41a
commit 2928eb7e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -82,6 +82,7 @@ export class Compiler {
this.contentBase = router.getBasePath()
const renderer = this._initRenderer()
this.heading = renderer.heading
let compile
const mdConf = config.markdown || {}
@ -403,6 +404,10 @@ export class Compiler {
return treeTpl(tree)
}
header(text, level) {
return this.heading(text, level)
}
article(text) {
return this.compile(text)
}

View File

@ -117,9 +117,9 @@ export function renderMixin(proto) {
const main = dom.getNode('#main')
const firstNode = main.children[0]
if (firstNode && firstNode.tagName !== 'H1') {
const h1 = dom.create('h1')
h1.innerText = activeEl.innerText
dom.before(main, h1)
const h1 = this.compiler.header(activeEl.innerText, 1)
const wrapper = dom.create('div', h1)
dom.before(main, wrapper.children[0])
}
}