fix(writer): 防静默丢章告警 + 占位符正则宽容化(大小写/全角冒号)

This commit is contained in:
lhl
2026-08-23 14:47:14 +08:00
parent 48a9624723
commit da33df92e1
10 changed files with 119 additions and 9 deletions
+26
View File
@@ -104,3 +104,29 @@ def test_parse_styles_collected(tmp_path):
assert "Heading 1" in result.styles["used"]
assert "Normal" in result.styles["used"]
assert "Heading 1" in result.styles["defined"]
def test_parse_extracts_placeholder_case_insensitive(tmp_path):
# 宽容:键名大小写不敏感 → 归一为小写 section:id
doc = new_document()
doc.add_paragraph("{{Section:2}}")
path = save_document(tmp_path, doc)
result = WordTemplateParser().parse(path)
assert result.placeholders == {"section:2": "{{Section:2}}"}
ph = [s for s in result.sections if s.type == "placeholder"]
assert [s.name for s in ph] == ["section:2"]
def test_parse_extracts_placeholder_fullwidth_colon(tmp_path):
# 宽容:全角冒号(:)也视为分隔符 → 归一为半角 section:id
doc = new_document()
doc.add_paragraph("{{section2}}")
path = save_document(tmp_path, doc)
result = WordTemplateParser().parse(path)
assert result.placeholders == {"section:2": "{{section2}}"}
ph = [s for s in result.sections if s.type == "placeholder"]
assert [s.name for s in ph] == ["section:2"]