Skip to content

Commit e80b776

Browse files
committed
fix(markdown): refine tokenizer and code handling in markdown utility
- Updated the tokenizer regex to simplify the matching of GitHub, Twitter, and Telegram mentions. - Refactored the code handling to correctly extract language and text for mermaid and other code blocks, improving output consistency. Signed-off-by: Innei <tukon479@gmail.com>
1 parent 9b46a60 commit e80b776

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

apps/core/src/modules/markdown/markdown.util.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ marked.use({
7070
return `<a target="_blank" class="mention" rel="noreferrer nofollow" href="${urlPrefix}${username}">${username}</a>`
7171
},
7272
tokenizer(src) {
73-
const rule =
74-
/^\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/
73+
const rule = /^(?<prefix>GH|TW|TG)@(?<name>\w+)\s?(?!\[.*?\])/
7574
const match = rule.exec(src)
7675
if (match) {
7776
const { groups } = match
@@ -149,12 +148,13 @@ marked.use({
149148
title || alt,
150149
)}</figcaption></figure>`
151150
},
152-
// @ts-ignore
153-
code(code, lang) {
151+
152+
code(code) {
153+
const { lang, text } = code
154154
if (lang == 'mermaid') {
155-
return `<pre class="mermaid">${code}</pre>`
155+
return `<pre class="mermaid">${text}</pre>`
156156
} else {
157-
return `<pre><code class="language-${lang}">${xss(code)}</code></pre>`
157+
return `<pre><code class="language-${lang}">${xss(text)}</code></pre>`
158158
}
159159
},
160160
},

0 commit comments

Comments
 (0)