From f1303f5270c45bb3e07945298ee2b0cb8c1d7352 Mon Sep 17 00:00:00 2001 From: Igor Klepacki Date: Thu, 26 Jun 2025 09:06:30 +0200 Subject: [PATCH] fix: proper assign of html custom icon node --- src/index.ts | 3 +- test/index.test.ts | 80 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index cd886eb..4b937eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -276,8 +276,9 @@ function createAlertComponent( .filter(Boolean) .join(' ') + // For component mode, we need to include raw HTML as an html node type const iconChildren = config.iconElementHtml - ? [{ type: 'text', value: config.iconElementHtml }] + ? [{ type: 'html', value: config.iconElementHtml }] : [] return { diff --git a/test/index.test.ts b/test/index.test.ts index 41bed48..df4d1e3 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -556,13 +556,89 @@ describe('remarkGitHubAlerts', () => { mode: 'component', alerts: { tip: { - iconElementHtml: 'tip-icon', + iconElementHtml: + '', }, }, } const result = await processMarkdown(markdown, options) - expect(result).toContain('tip-icon') + expect(result).toContain('' + ) + expect(result).toContain('') + }) + + it('should handle complex SVG icons in both modes', async () => { + const complexSvg = + '' + const markdown = `> [!WARNING] +> Complex SVG test.` + + // Test HTML mode + const htmlResult = await processMarkdown(markdown, { + mode: 'html', + alerts: { + warning: { + iconElementHtml: complexSvg, + }, + }, + }) + + expect(htmlResult).toContain(complexSvg) + expect(htmlResult).not.toContain('<svg') + expect(htmlResult).not.toContain('data-alert-type') + + // Test component mode + const componentResult = await processMarkdown(markdown, { + mode: 'component', + alerts: { + warning: { + iconElementHtml: complexSvg, + }, + }, + }) + + expect(componentResult).toContain(' { + const emojiIcon = '⚠️' + const markdown = `> [!CAUTION] +> Emoji icon test.` + + // Test HTML mode + const htmlResult = await processMarkdown(markdown, { + mode: 'html', + alerts: { + caution: { + iconElementHtml: emojiIcon, + }, + }, + }) + + expect(htmlResult).toContain(emojiIcon) + expect(htmlResult).not.toContain('data-alert-type') + + // Test component mode + const componentResult = await processMarkdown(markdown, { + mode: 'component', + alerts: { + caution: { + iconElementHtml: emojiIcon, + }, + }, + }) + + expect(componentResult).toContain(emojiIcon) + expect(componentResult).toContain('data-alert-type="caution"') }) })