优化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") html_template = resource_path("template/txt.html").read_text(encoding="utf-8")
# language=html # 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=document.content.decode()
body='\n'.join([r'<p>'+para+'</p>' for para in document.content.decode().split("\n")])
render = jinja2.Template(html_template).render( render = jinja2.Template(html_template).render(
title=document.stem, title=document.stem,
pico=pico,
body=body, body=body,
) )
return Document.from_bytes(content=render.encode("utf-8"), suffix=".html", stem=document.stem) return Document.from_bytes(content=render.encode("utf-8"), suffix=".html", stem=document.stem)

View File

@@ -3,15 +3,26 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{ title }}</title> <title>{{ title }}</title>
{{pico}}
<style> <style>
html { body{
padding: 2vh 10vw; padding: 0;
font-size: 15px; 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> </style>
</head> </head>
<body> <body>
{{ body }} <pre>{{ body }}</pre>
</body> </body>
</html> </html>