Skip to content

Commit 4476534

Browse files
committed
🤖 fix: prevent mdBook from parsing HTML as markdown
- Remove newlines from generated HTML to make it single-line - mdBook treats multi-line content as markdown, inserting <p> tags - Single-line HTML is passed through unchanged - Fixes HTML corruption in extension overview page
1 parent fd480e8 commit 4476534

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

scripts/mdbook-shiki.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function generateGridHtml(shikiHtml: string, originalCode: string): string {
6464

6565
/**
6666
* Process markdown content to replace code blocks with highlighted HTML
67+
* Wraps HTML in a special marker that mdBook won't process as markdown
6768
*/
6869
async function processMarkdown(content: string, highlighter: Awaited<ReturnType<typeof createHighlighter>>): Promise<string> {
6970
// Match ```lang\ncode\n``` blocks
@@ -96,7 +97,12 @@ async function processMarkdown(content: string, highlighter: Awaited<ReturnType<
9697
});
9798

9899
const gridHtml = generateGridHtml(html, code);
99-
result = result.replace(fullMatch, gridHtml);
100+
101+
// Remove newlines from HTML to prevent mdBook from treating it as markdown
102+
// mdBook only parses multi-line content as markdown; single-line HTML is passed through
103+
const singleLineHtml = gridHtml.replace(/\n/g, '');
104+
105+
result = result.replace(fullMatch, singleLineHtml);
100106
} catch (error) {
101107
console.warn(`[mdbook-shiki] Failed to highlight code block (${lang}):`, error);
102108
// Keep original code block on error

0 commit comments

Comments
 (0)