Skip to content

Commit 24c1b84

Browse files
author
Ming Di Leom
committedJun 7, 2024
fix(heading-link): compatibility with marked v12
hexojs/hexo-renderer-marked#280
1 parent a7dc49c commit 24c1b84

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎themes/chameleon/scripts/heading-link.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33

44
/*
55
* Add Link button next to a heading
6+
* based on https://github.com/hexojs/hexo-renderer-marked/blob/master/lib/renderer.js
67
*/
78

8-
const { slugize, stripHTML } = require('hexo-util')
9+
const { slugize, stripHTML, unescapeHTML: unescape } = require('hexo-util')
910

1011
const anchorId = (str, transformOption) => {
11-
return slugize(str.trim(), { transform: transformOption })
12+
return slugize(stripHTML(unescape(str)).trim(), { transform: transformOption });
1213
}
1314

1415
hexo.extend.filter.register('marked:renderer', function (renderer) {
1516
const { config } = this
1617
renderer.heading = function (text, level) {
17-
const transformOption = config.marked.modifyAnchors
18-
let id = anchorId(stripHTML(text), transformOption)
19-
const headingId = this._headingId
18+
const { modifyAnchors } = config.marked
19+
const transformOption = modifyAnchors;
20+
let id = anchorId(text, transformOption)
21+
const headingId = {};
2022

2123
// Add a number after id if repeated
2224
if (headingId[id]) {

0 commit comments

Comments
 (0)
Please sign in to comment.