5 * Add Link button next to a heading
8 const { slugize, stripHTML } = require('hexo-util')
10 const anchorId = (str, transformOption) => {
11 return slugize(str.trim(), { transform: transformOption })
14 hexo.extend.filter.register('marked:renderer', function (renderer) {
15 const { config } = this
16 renderer.heading = function (text, level) {
17 const transformOption = config.marked.modifyAnchors
18 let id = anchorId(stripHTML(text), transformOption)
19 const headingId = this._headingId
21 // Add a number after id if repeated
23 id += `-${headingId[id]++}`
29 return `<h${level} id="${id}">${text} <a href="#${id}" class="headerlink" title="${stripHTML(text)}">ยง</a></h${level}>`