Skip to content

Commit

Permalink
fix(#28): Solve heading parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Jan 24, 2020
1 parent 0ef6fe0 commit 8a9ca01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scripts/filters/post-heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ hexo.extend.filter.register('after_post_render', function (data) {
var regAttrId = tagNotEnd + attrId + tagNotEnd;
// Match the innermost 'h1~6' tags width the id attribute.
var regHTagInnermost = new RegExp(
`<${tagName}${regAttrId}>((?:(?!<\\/?${tagName}${regAttrId}>)(?:\\s|\\S))*?)<\/${tagName}>`,
`<(${tagName})${regAttrId}>((?:(?!<\\/?${tagName}${regAttrId}>)(?:\\s|\\S))*?)<\/${tagName}>`,
'gim'
);

data.content = data.content.replace(
regHTagInnermost,
function (match, attrBegin, id, attrEnd, html) {
function (match, tName, attrBegin, id, attrEnd, html) {
if (!id) {
return match;
}

var filterHtml = (html.replace(/<[^>]+>/gim, '') || '').trim();
return `
<h2 ${attrBegin} id="${id}" ${attrEnd}>
<${tName} ${attrBegin} id="${id}" ${attrEnd}>
<span class="heading-link">${filterHtml}</span>
</h2>
</${tName}>
`;
}
);
Expand Down

0 comments on commit 8a9ca01

Please sign in to comment.