Skip to content

Commit

Permalink
refactor: inject env to marked options
Browse files Browse the repository at this point in the history
so that plugins can use env too
  • Loading branch information
egoist committed Nov 18, 2018
1 parent 9ed2c4f commit 9c3850e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const store = new Vuex.Store({
file
}
let html = marked(text, {
renderer: markedRenderer(env, hooks),
highlight
renderer: markedRenderer(hooks),
highlight,
env
})
html = hooks.process('processHTML', html)
commit('SET_PAGE_TITLE', env.title)
Expand Down
5 changes: 3 additions & 2 deletions src/utils/markedRenderer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import marked from './marked'
import {slugify} from '.'

export default (env, hooks) => {
export default hooks => {
const renderer = new marked.Renderer()

env.headings = []
const slugs = []
renderer.heading = function(text, level, raw) {
const {env} = this.options

let slug = slugify(raw)
slugs.push(slug)
const sameSlugCount = slugs.filter(v => v === slug).length
Expand Down

0 comments on commit 9c3850e

Please sign in to comment.