diff --git a/scripts/events/lib/highlight.js b/scripts/events/lib/highlight.js index d50d6bf6..fc42843e 100644 --- a/scripts/events/lib/highlight.js +++ b/scripts/events/lib/highlight.js @@ -21,17 +21,17 @@ module.exports = (hexo) => { line_number: config.code.highlight.line_number || false }); - hexo.extend.filter.register('after_render:html', (html, data) => { + hexo.extend.filter.register('after_post_render', (page) => { if (config.code.highlight.highlightjs.bg_color) { - html = html.replace(/(?)(
]+?mermaid[^>]+?>/ims.test(p1)) {
return str.replace(/(class=".*?)hljs(.*?")/gims, '$1$2');
}
return `${p1}`;
});
- html = html.replace(/)()/gims, (str, p1) => {
+ page.content = page.content.replace(/(?)()/gims, (str, p1) => {
if (/]+?mermaid[^>]+?>/ims.test(p1)) {
return str.replace(/(class=".*?)hljs(.*?")/gims, '$1$2');
}
@@ -41,14 +41,14 @@ module.exports = (hexo) => {
if (hexo.config.highlight.line_number) {
// Mermaid block adaptation
- html = html.replace(/.*?().+?<\/figure>/gims, (str, p1) => {
+ page.content = page.content.replace(/.*?().+?<\/figure>/gims, (str, p1) => {
if (/]+?mermaid[^>]+?>/ims.test(p1)) {
return p1.replace(/(class=".*?)hljs(.*?")/gims, '$1$2').replace(/
/gims, '\n');
}
return str;
});
}
- return html;
+ return page;
});
} else if (config.code.highlight.lib === 'prismjs') {
// Force set hexo config
@@ -61,8 +61,8 @@ module.exports = (hexo) => {
line_number: config.code.highlight.line_number || false
});
- hexo.extend.filter.register('after_render:html', (html, data) => {
- html = html.replace(/(?)()/gims, (str, p1) => {
+ hexo.extend.filter.register('after_post_render', (page) => {
+ page.content = page.content.replace(/(?)()/gims, (str, p1) => {
if (/]+?mermaid[^>]+?>/ims.test(p1)) {
str = str.replace(/]*?>/gims, '')
.replace(/(class=".*?)language-mermaid(.*?")/gims, '$1mermaid$2');
@@ -73,7 +73,7 @@ module.exports = (hexo) => {
}
return `${p1}`;
});
- return html;
+ return page;
});
}
};