Skip to content

Commit

Permalink
fix: code block not working for x86asm #467
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanNotFound committed Dec 1, 2024
1 parent 7e83095 commit 73d1956
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
30 changes: 20 additions & 10 deletions scripts/helpers/theme-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,35 @@ hexo.extend.helper.register("isHomePagePagination", function (pagePath, route) {

/* code block language display */
hexo.extend.filter.register("after_post_render", function (data) {
const pattern = /<figure class="highlight ([a-zA-Z+\-/#]+)">.*?<\/figure>/g;
data.content = data.content.replace(pattern, function (match, p1) {
// Only process if not already processed
if (data._processedHighlight) return data;

// Updated pattern to include numbers and other special characters
const pattern = /<figure class="highlight ([^"]+)">([\s\S]*?)<\/figure>/g;
data.content = data.content.replace(pattern, function (match, p1, p2) {
// If already has code-container anywhere in the match, return unchanged
if (match.includes('code-container')) {
return match;
}

let language = p1 || "code";
if (language === "plain") {
language = "code";
}
const replaced = match.replace(
'<figure class="highlight ',
'<figure class="iseeu highlight ',
);
const container =
'<div class="highlight-container" data-rel="' +

return '<div class="code-container" data-rel="' +
language.charAt(0).toUpperCase() +
language.slice(1) +
'">' +
replaced +
match.replace(
'<figure class="highlight ',
'<figure class="iseeu highlight '
) +
"</div>";
return container;
});

// Mark as processed
data._processedHighlight = true;
return data;
});

Expand Down
Loading

0 comments on commit 73d1956

Please sign in to comment.