feat: refine table presentation and editable Word export

This commit is contained in:
2026-11-04 15:40:52 +08:00
parent 31d0ccfde5
commit 3bb2cc5438
15 changed files with 337 additions and 58 deletions
+8 -2
View File
@@ -8,6 +8,7 @@ from __future__ import annotations
import math
import re
from typing import Any
from .table_style import TABLE_OPTIONS, TABLE_BOOL_FIELDS
STYLE_TARGETS = (
("paragraph", "正文段落", ".reader p:not(:where(li p, blockquote p, .admonition p, th p, td p))"),
@@ -61,13 +62,14 @@ def normalize_rule(value: object) -> dict[str, Any]:
if field + "_value" in rule:
unit = rule.get(field + "_unit", "multiple")
rule[field + "_unit"] = "em" if unit == "multiple" else unit
for key in BOOL_FIELDS:
for key in (*BOOL_FIELDS, *TABLE_BOOL_FIELDS):
if key in rule and not isinstance(rule[key], bool):
rule.pop(key)
for key in ('font_color', 'background_color', 'border_color'):
for key in ('font_color', 'background_color', 'border_color', 'table_stripe_color'):
if key in rule and not re.fullmatch(r"auto|transparent|inherit|#[0-9a-fA-F]{6}", str(rule[key])):
rule.pop(key)
for key, allowed in {"alignment": {"left", "center", "right", "justify"},
'table_border_mode': {'grid', 'horizontal', 'none'},
"border_style": {'none','hidden','solid','dotted','dashed','double','groove','ridge','inset','outset'},
"indent_mode": {"none", "first", "hanging"},
"line_spacing_mode": {"multiple", "exact", "at_least"}}.items():
@@ -192,6 +194,10 @@ def css_declarations(value: dict) -> list[str]:
out.append(f"border-style: {r['border_style']};")
if 'cell_padding' in r:
out.append(f"padding: {fmt(r['cell_padding'])}pt;")
for field, prop in TABLE_OPTIONS.items():
if field in r:
value = str(r[field]).lower() if field in TABLE_BOOL_FIELDS else r[field]
out.append(f'{prop}: {value};')
if 'list_marker' in r:
out.append(f"list-style-type: {r['list_marker']};")
if 'level_indent' in r: