Files
wehub-resource-sync 925e56bb5f
Unit tests / build (t4_gpu) (push) Has been cancelled
Unit tests / build (ubuntu-latest) (push) Has been cancelled
Unit tests / build (windows-latest) (push) Has been cancelled
Test CLI scripts / build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:56 +08:00

64 lines
2.0 KiB
JavaScript

<style>
.katex-display-container {
display: inline-block;
max-width: 100%;
overflow-x: auto;
max-height: 100%;
}
.katex-inline-container {
display: inline-block;
max-width: 100%;
overflow-x: auto;
max-height: 100%;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.js" onload="setTimeout(function() {renderMath()})" async></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css">
<script>
function htmlUnescape(escapedText) {
const htmlEntities = {
'&amp;': '&',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&#39;': "'",
'&nbsp;': ' '
};
return escapedText.replace(/&amp;|&lt;|&gt;|&quot;|&#39;|&nbsp;/g, match => htmlEntities[match]);
}
const renderMath = (function() {
try {
const mathElements = document.querySelectorAll('math');
mathElements.forEach(function(element) {
let mathContent = element.innerHTML.trim();
mathContent = htmlUnescape(mathContent);
const isDisplay = element.getAttribute('display') === 'block';
const container = document.createElement('span');
container.className = isDisplay ? 'katex-display-container' : 'katex-inline-container';
element.parentNode.insertBefore(container, element);
try {
katex.render(mathContent, container, {
displayMode: isDisplay,
throwOnError: false
});
} catch (err) {
console.error('KaTeX rendering error:', err);
container.textContent = mathContent; // Fallback to raw text
}
element.parentNode.removeChild(element);
});
console.log('Math rendering complete with', mathElements.length, 'expressions');
} catch (err) {
console.error('Error in renderMath function:', err);
}
});
</script>