fix: preserve inherited character indents in Word lists

This commit is contained in:
2026-10-29 14:53:18 +08:00
parent 7f9e7ff01b
commit 9867553bfe
2 changed files with 9 additions and 2 deletions
+8 -2
View File
@@ -163,8 +163,14 @@ def apply_docx_styles(path: Path, rules: dict | None = None, *, font_family: str
if target == "list" and level is not None and number(level.get(W + "val")) > 0:
# Retain nested list levels while applying the selected base indent.
paragraph_rule = dict(rule)
paragraph_rule["left_indent_value"] = length_points(rule["left_indent_value"], rule["left_indent_unit"], font_points(rule)) + number(level.get(W + "val")) * 36
paragraph_rule["left_indent_unit"] = "pt"
offset = number(level.get(W + "val")) * 36
if rule["left_indent_unit"] == "em":
# A style's leftChars takes precedence over a direct left value;
# keep the coordinate system to override that inherited value.
paragraph_rule["left_indent_value"] = number(rule["left_indent_value"]) + offset / font_points(rule)
else:
paragraph_rule["left_indent_value"] = length_points(rule["left_indent_value"], rule["left_indent_unit"], font_points(rule)) + offset
paragraph_rule["left_indent_unit"] = "pt"
_paragraph_properties(ppr, paragraph_rule)
for run in paragraph.iter(W + "r"):
rpr = properties(run, "rPr")
+1
View File
@@ -177,3 +177,4 @@ def test_pandoc_style_processing_preserves_math_links_and_numbering(tmp_path):
levels = xml.findall(".//w:pPr[w:numPr]", NS)
nested = [p for p in levels if p.find("w:numPr/w:ilvl", NS).get(W + "val") == "1"]
assert nested and int(nested[0].find(W + "ind").get(W + "left")) > 720
assert nested[0].find(W + "ind").get(W + "leftChars") == "500"