From 24c1b84e33b228fd838f2e1861f7e44b84b43ae8 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Fri, 7 Jun 2024 12:38:33 +0000 Subject: [PATCH] fix(heading-link): compatibility with marked v12 https://github.com/hexojs/hexo-renderer-marked/pull/280 --- themes/chameleon/scripts/heading-link.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/themes/chameleon/scripts/heading-link.js b/themes/chameleon/scripts/heading-link.js index 7e71823..107d0b0 100644 --- a/themes/chameleon/scripts/heading-link.js +++ b/themes/chameleon/scripts/heading-link.js @@ -3,20 +3,22 @@ /* * Add Link button next to a heading +* based on https://github.com/hexojs/hexo-renderer-marked/blob/master/lib/renderer.js */ -const { slugize, stripHTML } = require('hexo-util') +const { slugize, stripHTML, unescapeHTML: unescape } = require('hexo-util') const anchorId = (str, transformOption) => { - return slugize(str.trim(), { transform: transformOption }) + return slugize(stripHTML(unescape(str)).trim(), { transform: transformOption }); } hexo.extend.filter.register('marked:renderer', function (renderer) { const { config } = this renderer.heading = function (text, level) { - const transformOption = config.marked.modifyAnchors - let id = anchorId(stripHTML(text), transformOption) - const headingId = this._headingId + const { modifyAnchors } = config.marked + const transformOption = modifyAnchors; + let id = anchorId(text, transformOption) + const headingId = {}; // Add a number after id if repeated if (headingId[id]) {