Fix first-page line numbering off-by-one in transcript DOCX
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

- Remove docGrid element to prevent phantom grid-based line offset.
- Ensure exactly one lnNumType element (no duplicates).
- First visible line on page 1 now correctly numbered as 1.
This commit is contained in:
admin
2026-06-16 19:09:26 +00:00
parent f20102d564
commit 670c6d3e2b
+8 -5
View File
@@ -318,7 +318,7 @@ def _create_transcript_section_properties(section):
- Margins: 1 inch all sides - Margins: 1 inch all sides
- Single column layout - Single column layout
- Line numbering: start=1, countBy=1, restart each page - Line numbering: start=1, countBy=1, restart each page
- Disable document grid to avoid off-by-one line numbering - Remove document grid to avoid off-by-one line numbering
""" """
sectPr = section._sectPr sectPr = section._sectPr
@@ -341,10 +341,13 @@ def _create_transcript_section_properties(section):
_set_element_attr(cols, "num", "1") _set_element_attr(cols, "num", "1")
_set_element_attr(cols, "space", "720") _set_element_attr(cols, "space", "720")
# Disable document grid to avoid Word counting phantom grid lines # Remove document grid entirely to avoid phantom grid-based line numbering
docGrid = sectPr.find(f"{{{W_NS}}}docGrid") for docGrid in sectPr.findall(f"{{{W_NS}}}docGrid"):
if docGrid is not None: sectPr.remove(docGrid)
_set_element_attr(docGrid, "type", "none")
# Ensure exactly one lnNumType element (remove any existing)
for lnNumType in sectPr.findall(f"{{{W_NS}}}lnNumType"):
sectPr.remove(lnNumType)
# Line numbering: start=1, countBy=1, restart each page # Line numbering: start=1, countBy=1, restart each page
lnNumType = OxmlElement("w:lnNumType") lnNumType = OxmlElement("w:lnNumType")