mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-22 01:15:25 +03:00
fix: render lang of code block
This commit is contained in:
parent
714b8d2bb1
commit
0ada9e0448
1 changed files with 3 additions and 4 deletions
|
@ -60,10 +60,9 @@ export function contentToVNode(
|
|||
return `:${name}:`
|
||||
})
|
||||
// handle code frames
|
||||
.replace(/<p>(```|~~~)([\s\S]+?)\1/g, (_1, _2, raw) => {
|
||||
const plain = htmlToText(`<p>${raw}</p>`).trim()
|
||||
const [lang, ...rest] = plain.split(/\n/)
|
||||
return `<custom-code lang="${lang?.trim().toLowerCase() || ''}" code="${encodeURIComponent(rest.join('\n'))}"></custom-code>`
|
||||
.replace(/<p>(```|~~~)([\w]*)([\s\S]+?)\1/g, (_1, _2, lang, raw) => {
|
||||
const code = htmlToText(`<p>${raw}</p>`)
|
||||
return `<custom-code lang="${lang?.trim().toLowerCase() || ''}" code="${encodeURIComponent(code)}"></custom-code>`
|
||||
})
|
||||
|
||||
const tree = parseFragment(content)
|
||||
|
|
Loading…
Reference in a new issue