Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure autoHeader dom result is similar to parsed H1 #811

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}

Expand Down Expand Up @@ -381,6 +382,10 @@ export class Compiler {
return treeTpl(tree)
}

header(text, level) {
return this.heading(text, level)
}

article(text) {
return this.compile(text)
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,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])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because h1 is returned as a String, I use this trick to convert it into a DOM node

}
}

Expand Down