Skip to content

Commit

Permalink
兼容老代码
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Apr 12, 2024
1 parent 21859bb commit c14ee6b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions theme/blog/statics/scripts/header.js
Expand Up @@ -55,6 +55,17 @@ TaoBlog.fn.externAnchor = function() {

// 代码高亮
TaoBlog.fn.highlight = function(pre) {
// 早期代码兼容:
// <pre class="code" lang="cpp"></pre>
{
if (pre.classList.contains('code') && pre.getAttribute('lang') != '' && !pre.firstElementChild) {
let code = document.createElement('code');
code.innerHTML = pre.innerHTML;
code.classList.add(`language-${pre.getAttribute('lang')}`);
pre.innerHTML = '';
pre.appendChild(code);
}
}
// 必须是 <pre><code class="language-xxx"></code></pre>
{
let code = pre.querySelector(':scope > code');
Expand Down

0 comments on commit c14ee6b

Please sign in to comment.