From 84a2de2791114f43216aba4d29debce745761256 Mon Sep 17 00:00:00 2001 From: KeJun Date: Fri, 1 Dec 2023 23:31:43 +0800 Subject: [PATCH] fix: using custom token rendering (#3) --- src/index.ts | 15 +++++++++++---- test/output/1.basic.html | 13 +++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 90c0233..7b4d9d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,15 +80,22 @@ const MarkdownItGitHubAlerts: MarkdownIt.PluginWithOptions

${icon}${title}

` - close.type = 'html_block' + open.meta = { + title, + type, + icon, + } + close.type = 'alert_close' close.tag = 'div' - close.content = '' } } }) + md.renderer.rules.alert_open = function (tokens, idx) { + const { title, type, icon } = tokens[idx].meta + return `

${icon}${title}

` + } } function capitalize(str: string) { diff --git a/test/output/1.basic.html b/test/output/1.basic.html index 363c526..105e633 100644 --- a/test/output/1.basic.html +++ b/test/output/1.basic.html @@ -1,10 +1,15 @@

Hello

Note

Highlights information that users should take into account, even when skimming.

-

Tip

Optional information to help a user be more successful.

-

Important

Crucial information necessary for users to succeed.

-

Warning

Critical content demanding immediate user attention due to potential risks.

-

Caution

Negative potential consequences of an action.

+

Tip

Optional information to help a user be more successful.

+
+

Important

Crucial information necessary for users to succeed.

+
+

Warning

Critical content demanding immediate user attention due to potential risks.

+
+

Caution

Negative potential consequences of an action.

+
+