Skip to content

Commit

Permalink
fix: unsanitize HTML entities in code block before highlighting (#2181)
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart authored Feb 6, 2025
1 parent 7b9c22b commit c3aad83
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composables/useShiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default function useShiki(options = {immediate: false}) {
// check is there is a language class and extract it
const languageClass = Array.from(preClassList).find((c) => c.startsWith('language-'))
if(languageClass) {
const html = (await shiki.value)?.codeToHtml(block.innerHTML.replace(/\n$/, ''), {
const originalCode = block.innerHTML.replace(/\n$/, '').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&')
const html = (await shiki.value)?.codeToHtml(originalCode, {
lang: languageClass.replace('language-', ''),
theme: 'github-dark'
})
Expand All @@ -80,6 +81,7 @@ export default function useShiki(options = {immediate: false}) {
if(classList) {
block.parentElement?.classList.add(...classList)
}

block.innerHTML = innerHTML.replace(/\n/g, '')
}
// add mb-3 to the block-code element
Expand Down

0 comments on commit c3aad83

Please sign in to comment.