Skip to content

Commit

Permalink
🔥 (#412
Browse files Browse the repository at this point in the history
  • Loading branch information
everfu committed Nov 8, 2024
1 parent b9ae94b commit 4e63835
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ const addHighlight = () => {
if ($isPrismjs) {
$syntaxHighlight.forEach(item => {
const langName = item.getAttribute('data-language') || 'Code'
const highlightLangEle = `<div class="code-lang">${langName}</div>`
const highlightLangEle = `<div class="code-lang">${utils.escapeHtml(langName)}</div>`
utils.wrap(item, 'figure', {
class: 'highlight'
})
Expand All @@ -562,7 +562,7 @@ const addHighlight = () => {
$syntaxHighlight.forEach(item => {
let langName = item.getAttribute('class').split(' ')[1]
if (langName === 'plain' || langName === undefined) langName = 'Code'
const highlightLangEle = `<div class="code-lang">${langName}</div>`
const highlightLangEle = `<div class="code-lang">${utils.escapeHtml(langName)}</div>`
createEle(highlightLangEle, item, 'hl')
})
}
Expand Down
10 changes: 10 additions & 0 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@

observerItem ? observerItem.observe(dom) : callback();
},
escapeHtml: function (unsafe) {
return unsafe.replace(/[&<"']/g, function (m) {
return {
'&': '&amp;',
'<': '&lt;',
'"': '&quot;',
"'": '&#039;'
}[m];
});
}
}
window.utils = {...window.utils, ...utilsFn};
})()

0 comments on commit 4e63835

Please sign in to comment.