diff --git a/mdhelper/docx_style.py b/mdhelper/docx_style.py index 15c50dd..cfbaa4a 100644 --- a/mdhelper/docx_style.py +++ b/mdhelper/docx_style.py @@ -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") diff --git a/tests/test_document_style.py b/tests/test_document_style.py index 0292bc2..8b8c630 100644 --- a/tests/test_document_style.py +++ b/tests/test_document_style.py @@ -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"