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>
This commit is contained in:
@@ -70,8 +70,7 @@ marked.use({
|
|||||||
return `<a target="_blank" class="mention" rel="noreferrer nofollow" href="${urlPrefix}${username}">${username}</a>`
|
return `<a target="_blank" class="mention" rel="noreferrer nofollow" href="${urlPrefix}${username}">${username}</a>`
|
||||||
},
|
},
|
||||||
tokenizer(src) {
|
tokenizer(src) {
|
||||||
const rule =
|
const rule = /^(?<prefix>GH|TW|TG)@(?<name>\w+)\s?(?!\[.*?\])/
|
||||||
/^\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/
|
|
||||||
const match = rule.exec(src)
|
const match = rule.exec(src)
|
||||||
if (match) {
|
if (match) {
|
||||||
const { groups } = match
|
const { groups } = match
|
||||||
@@ -149,12 +148,13 @@ marked.use({
|
|||||||
title || alt,
|
title || alt,
|
||||||
)}</figcaption></figure>`
|
)}</figcaption></figure>`
|
||||||
},
|
},
|
||||||
// @ts-ignore
|
|
||||||
code(code, lang) {
|
code(code) {
|
||||||
|
const { lang, text } = code
|
||||||
if (lang == 'mermaid') {
|
if (lang == 'mermaid') {
|
||||||
return `<pre class="mermaid">${code}</pre>`
|
return `<pre class="mermaid">${text}</pre>`
|
||||||
} else {
|
} else {
|
||||||
return `<pre><code class="language-${lang}">${xss(code)}</code></pre>`
|
return `<pre><code class="language-${lang}">${xss(text)}</code></pre>`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user