优化txt译文显示效果

This commit is contained in:
xunbu
2025-10-10 11:18:32 +08:00
parent 6fb3bae5a5
commit 4780a2b19a
2 changed files with 17 additions and 9 deletions

View File

@@ -26,12 +26,9 @@ class TXT2HTMLExporter(TXTExporter):
html_template = resource_path("template/txt.html").read_text(encoding="utf-8")
# language=html
pico = f'<style>{resource_path("static/pico.css").read_text(encoding="utf-8")}</style>' if not cdn else r'<link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/picocss/2.1.1/pico.min.css" integrity="sha512-+4kjFgVD0n6H3xt19Ox84B56MoS7srFn60tgdWFuO4hemtjhySKyW4LnftYZn46k3THUEiTTsbVjrHai+0MOFw==" crossorigin="anonymous" referrerpolicy="no-referrer" />'
body='\n'.join([r'<p>'+para+'</p>' for para in document.content.decode().split("\n")])
body=document.content.decode()
render = jinja2.Template(html_template).render(
title=document.stem,
pico=pico,
body=body,
)
return Document.from_bytes(content=render.encode("utf-8"), suffix=".html", stem=document.stem)

View File

@@ -3,15 +3,26 @@
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
{{pico}}
<style>
html {
padding: 2vh 10vw;
font-size: 15px;
body{
padding: 0;
margin: 0;
}
pre {
width: 100%;
height: 95%;
border: none;
margin: 0;
padding: 0;
overflow: auto;
background-color: var(--bs-body-bg);
display: block;
font-size: 14px;
line-height: 21px;
}
</style>
</head>
<body>
{{ body }}
<pre>{{ body }}</pre>
</body>
</html>