weasyprint renders <pre> blocks with monospace fonts that lack CJK glyphs, causing Chinese/Japanese/Korean characters to display as garbled text. Fix: add _fix_cjk_code_blocks() preprocessor that detects CJK in <pre><code> and converts to <div class="cjk-code-block"> with inherited body font. Pure-ASCII code blocks are left untouched. Also adds code/pre/pre-code CSS rules to both themes (default + warm-terra) that were previously missing entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
132 lines
2.6 KiB
CSS
132 lines
2.6 KiB
CSS
/*
|
|
* Default — PDF theme for formal documents
|
|
*
|
|
* Color palette: black/grey, no accent color
|
|
* Font: Songti SC (body) + Heiti SC (headings)
|
|
* Best for: legal documents, trademark filings, contracts, formal reports
|
|
*
|
|
* This is the original built-in theme from md_to_pdf.py, extracted for reference.
|
|
*/
|
|
|
|
@page {
|
|
size: A4;
|
|
margin: 2.5cm 2cm;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Songti SC', 'SimSun', 'STSong', 'Noto Serif CJK SC', serif;
|
|
font-size: 12pt;
|
|
line-height: 1.8;
|
|
color: #000;
|
|
width: 100%;
|
|
}
|
|
|
|
h1 {
|
|
font-family: 'Heiti SC', 'SimHei', 'STHeiti', 'Noto Sans CJK SC', sans-serif;
|
|
font-size: 18pt;
|
|
font-weight: bold;
|
|
text-align: center;
|
|
margin-top: 0;
|
|
margin-bottom: 1.5em;
|
|
}
|
|
|
|
h2 {
|
|
font-family: 'Heiti SC', 'SimHei', 'STHeiti', 'Noto Sans CJK SC', sans-serif;
|
|
font-size: 14pt;
|
|
font-weight: bold;
|
|
margin-top: 1.5em;
|
|
margin-bottom: 0.8em;
|
|
}
|
|
|
|
h3 {
|
|
font-family: 'Heiti SC', 'SimHei', 'STHeiti', 'Noto Sans CJK SC', sans-serif;
|
|
font-size: 12pt;
|
|
font-weight: bold;
|
|
margin-top: 1em;
|
|
margin-bottom: 0.5em;
|
|
}
|
|
|
|
p {
|
|
margin: 0.8em 0;
|
|
text-align: justify;
|
|
}
|
|
|
|
ul, ol {
|
|
margin: 0.8em 0;
|
|
padding-left: 2em;
|
|
}
|
|
|
|
li {
|
|
margin: 0.4em 0;
|
|
}
|
|
|
|
table {
|
|
border-collapse: collapse;
|
|
width: 100%;
|
|
margin: 1em 0;
|
|
font-size: 10pt;
|
|
table-layout: fixed;
|
|
}
|
|
|
|
th, td {
|
|
border: 1px solid #666;
|
|
padding: 8px 6px;
|
|
text-align: left;
|
|
overflow-wrap: break-word;
|
|
word-break: normal;
|
|
}
|
|
|
|
th {
|
|
background-color: #f0f0f0;
|
|
font-weight: bold;
|
|
}
|
|
|
|
hr {
|
|
border: none;
|
|
border-top: 1px solid #ccc;
|
|
margin: 1.5em 0;
|
|
}
|
|
|
|
code {
|
|
font-family: 'Menlo', 'PingFang SC', 'Heiti SC', 'Noto Sans CJK SC', monospace;
|
|
background: #f5f5f5;
|
|
padding: 1px 4px;
|
|
border-radius: 3px;
|
|
font-size: 10pt;
|
|
}
|
|
|
|
pre {
|
|
background: #f5f5f5;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
padding: 12px 16px;
|
|
margin: 1em 0;
|
|
overflow-wrap: break-word;
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|
|
|
|
pre code {
|
|
font-family: 'Menlo', 'PingFang SC', 'Heiti SC', 'Noto Sans CJK SC', monospace;
|
|
background: none;
|
|
padding: 0;
|
|
border-radius: 0;
|
|
font-size: 9pt;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
/* CJK code blocks converted to styled divs by preprocessor.
|
|
Uses inherit to reuse body's CJK font (weasyprint may not find PingFang SC). */
|
|
.cjk-code-block {
|
|
font-family: inherit;
|
|
background: #f5f5f5;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
padding: 12px 16px;
|
|
margin: 1em 0;
|
|
font-size: 10pt;
|
|
line-height: 1.8;
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|