Skip to content

Commit e7c5225

Browse files
author
LittleLobster
committed
Fix blog markdown image rendering
1 parent 7523194 commit e7c5225

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

web/scripts/build-blog.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function md2html(md) {
2727
// Bold + italic
2828
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
2929
.replace(/\*(.+?)\*/g, '<em>$1</em>')
30+
// Images (must run before links)
31+
.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1" />')
3032
// Links
3133
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
3234
// Horizontal rules
@@ -52,7 +54,7 @@ function md2html(md) {
5254
.map(block => {
5355
block = block.trim();
5456
if (!block) return '';
55-
if (/^<(h[1-6]|ul|ol|pre|table|div|hr|section)/.test(block)) return block;
57+
if (/^<(h[1-6]|ul|ol|pre|table|div|hr|section|img)/.test(block)) return block;
5658
return `<p>${block}</p>`;
5759
})
5860
.join('\n\n');

0 commit comments

Comments
 (0)