fix: code block

This commit is contained in:
ccbikai
2024-08-13 19:20:45 +08:00
parent 1cd7fcb22c
commit 8d2520b858
2 changed files with 9 additions and 1 deletions

View File

@@ -17,6 +17,12 @@
width: calc(100% - var(--box-margin));
}
> pre {
width: calc(100% - var(--box-margin));
max-width: 456px;
overflow-x: auto;
}
.tgme_widget_message_link_preview {
margin-top: 16px;
display: none;

View File

@@ -112,8 +112,10 @@ function modifyHTMLContent($, content, { index } = {}) {
})
$(content).find('pre').each((_index, pre) => {
try {
$(pre).find('br')?.replaceWith('\n')
const code = $(pre).text()
const language = flourite(code, { shiki: true })?.language
const language = flourite(code, { shiki: true, noUnknown: true })?.language || 'text'
const highlightedCode = prism.highlight(code, prism.languages[language], language)
$(pre).html(`<code class="language-${language}">${highlightedCode}</code>`)
}