Files
docutranslate/docutranslate/template/markdown.html
2026-01-06 20:22:26 +08:00

215 lines
5.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{title}}</title>
{{pico}}
{{katexCss}}
<link rel="stylesheet" href="/static/katex/copy-tex.min.css">
{{katexJs}}
<script src="/static/katex/copy-tex.min.js"></script>
{{autoRender}}
<style>
@page {
margin: 1.5cm 1cm 1.5cm 2cm;
@top-left {
content: "{{title}}";
font-size: 10pt;
color: #666;
}
@top-right {
content: counter(page);
font-size: 10pt;
color: #666;
}
@bottom-left {
content: "Powered by DocuTranslate";
font-size: 8pt;
color: #999;
}
@bottom-right {
content: counter(page) " / " counter(pages);
font-size: 10pt;
color: #666;
}
}
@media print {
#toc-toggle, #toc-sidebar {
display: none !important;
}
html {
padding: 0 !important;
}
main {
padding: 0 !important;
}
}
html {
font-size: 15px;
}
main {
padding: 2vh 10vw;
}
#toc-toggle {
position: fixed;
left: 10px;
top: 50%;
transform: translateY(-50%);
width: 30px;
height: 60px;
background: #f0f0f0;
border: 1px solid #ddd;
border-radius: 0 5px 5px 0;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
color: #666;
z-index: 1000;
opacity: 0;
transition: opacity 0.2s;
}
#toc-toggle:hover {
background: #e0e0e0;
}
body:hover #toc-toggle {
opacity: 1;
}
#toc-sidebar {
position: fixed;
left: -280px;
top: 0;
width: 280px;
height: 100vh;
background: #fafafa;
border-right: 1px solid #ddd;
overflow-y: auto;
z-index: 999;
transition: left 0.3s ease;
padding: 20px;
box-sizing: border-box;
}
#toc-sidebar.open {
left: 0;
}
#toc-sidebar h3 {
margin-top: 0;
margin-bottom: 15px;
font-size: 16px;
color: #333;
border-bottom: 1px solid #ddd;
padding-bottom: 10px;
}
#toc-list {
list-style: none;
padding: 0;
margin: 0;
}
#toc-list li {
margin: 5px 0;
font-size: 13px;
}
#toc-list li a {
color: #555;
text-decoration: none;
display: block;
padding: 3px 0;
}
#toc-list li a:hover {
color: #007bff;
}
#toc-list .toc-h1 { margin-left: 0; font-weight: 600; }
#toc-list .toc-h2 { margin-left: 15px; }
#toc-list .toc-h3 { margin-left: 30px; font-size: 12px; }
#toc-list .toc-h4 { margin-left: 45px; font-size: 12px; }
#toc-list .toc-h5 { margin-left: 60px; font-size: 11px; color: #888; }
#toc-list .toc-h6 { margin-left: 75px; font-size: 11px; color: #888; }
</style>
</head>
<body>
<!-- Toggle Button -->
<div id="toc-toggle" title="目录"></div>
<!-- Sidebar TOC -->
<div id="toc-sidebar">
<h3>目录</h3>
<ul id="toc-list"></ul>
</div>
<!-- Main Content -->
<main>
{{markdown}}
</main>
</body>
{{renderMathInElement}}
{{mermaid}}
<script>
// Generate TOC from headings
function generateTOC() {
const main = document.querySelector('main');
const headings = main.querySelectorAll('h1, h2, h3, h4, h5, h6');
const tocList = document.getElementById('toc-list');
if (headings.length === 0) {
document.getElementById('toc-toggle').style.display = 'none';
return;
}
headings.forEach((heading, index) => {
if (!heading.id) {
heading.id = 'heading-' + index;
}
const level = heading.tagName.toLowerCase();
const text = heading.textContent;
const li = document.createElement('li');
li.className = 'toc-' + level;
li.innerHTML = `<a href="#${heading.id}">${text}</a>`;
tocList.appendChild(li);
});
}
// Toggle sidebar
function toggleTOC() {
const sidebar = document.getElementById('toc-sidebar');
sidebar.classList.toggle('open');
}
document.getElementById('toc-toggle').addEventListener('click', toggleTOC);
// Generate TOC after content loads
generateTOC();
setTimeout(() => {
const KatexErrors = document.getElementsByClassName("katex-error")
for (const katexError of KatexErrors) {
katexError.innerHTML = katexError.title
}
}, 200)
</script>
<script>
mermaid.initialize({
securityLevel: 'loose',
startOnLoad: true
});
</script>
</html>