feat: standardize Word export and Office conversion
This commit is contained in:
1 parent
5be21f2c3d
commit
c5eefe60f0
12 files changed
+410
-60
No files matched your search
@@ -41,8 +41,10 @@ def test_formal_docx_contains_required_layout_numbering_and_embedded_font(tmp_pa
|
||||
## 一、一级标题
|
||||
这是正文,用于验证首行缩进、两端对齐和固定行距。
|
||||
|
||||
### (一)二级标题
|
||||
#### 1. 三级标题
|
||||
### 2.1 二级标题
|
||||
#### 2.1.1 三级标题
|
||||
|
||||
---
|
||||
|
||||
表1 测试表格
|
||||
| 项目 | 数值 |
|
||||
@@ -77,8 +79,11 @@ def test_formal_docx_contains_required_layout_numbering_and_embedded_font(tmp_pa
|
||||
assert '<w:pStyle w:val="DocumentTitle"/>' in document
|
||||
assert "方正小标宋简体" in document
|
||||
assert "一、一级标题" not in document
|
||||
assert "(一)二级标题" not in document
|
||||
assert "1. 三级标题" not in document
|
||||
assert "2.1 二级标题" not in document
|
||||
assert "2.1.1 三级标题" not in document
|
||||
assert "────────" not in document
|
||||
assert "二级标题" in document
|
||||
assert "三级标题" in document
|
||||
|
||||
assert 'w:line="579" w:lineRule="exact"' in styles
|
||||
assert '<w:ind w:left="0" w:hanging="0" w:firstLineChars="200"/>' in styles
|
||||
@@ -86,11 +91,13 @@ def test_formal_docx_contains_required_layout_numbering_and_embedded_font(tmp_pa
|
||||
assert 'w:val="44"' in styles
|
||||
assert "仿宋" in styles and 'w:val="32"' in styles
|
||||
assert "宋体" in styles and 'w:val="28"' in styles
|
||||
assert styles.count('w:firstLineChars="200"') >= 6
|
||||
|
||||
assert '<w:numFmt w:val="chineseCounting"/>' in numbering
|
||||
assert '<w:lvlText w:val="%1、"/>' in numbering
|
||||
assert '<w:lvlText w:val="(%2)"/>' in numbering
|
||||
assert '<w:lvlText w:val="(%2)"/>' in numbering
|
||||
assert '<w:lvlText w:val="%3."/>' in numbering
|
||||
assert numbering.count('w:firstLineChars="200"') == 3
|
||||
assert '<w:evenAndOddHeaders/>' in settings
|
||||
assert '<w:updateFields w:val="true"/>' in settings
|
||||
|
||||
@@ -114,3 +121,20 @@ def test_export_rejects_wrong_font(tmp_path: Path) -> None:
|
||||
|
||||
with pytest.raises(word_export.WordExportFontError):
|
||||
word_export.build_markdown_docx("正文", font_path=wrong_font)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "expected"),
|
||||
[
|
||||
("一、一级标题", "一级标题"),
|
||||
("(一) 二级标题", "二级标题"),
|
||||
("(一)二级标题", "二级标题"),
|
||||
("1. 三级标题", "三级标题"),
|
||||
("2.1 二级标题", "二级标题"),
|
||||
("2.1.1 三级标题", "三级标题"),
|
||||
("2.1.1. 三级标题", "三级标题"),
|
||||
("正文标题", "正文标题"),
|
||||
],
|
||||
)
|
||||
def test_manual_heading_number_is_removed_as_one_complete_prefix(source: str, expected: str) -> None:
|
||||
assert word_export._strip_manual_heading_number(source) == expected
|
||||
Reference in new issue
Block a user