Fix transcript DOCX line numbering starting at 2 (docGrid)
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

- Disable document grid (w:type='none') when enabling line numbering
- Prevents Word from treating an empty grid line as line 1
This commit is contained in:
admin
2026-06-16 16:00:09 +00:00
parent 0b3f737e5b
commit 8ff473f3e6
+6
View File
@@ -327,9 +327,15 @@ def _configure_section_margins(doc, margin=1.0):
def _enable_line_numbering(section, start_at=1, count_by=1, restart=True): def _enable_line_numbering(section, start_at=1, count_by=1, restart=True):
""" """
Enable line numbering for a specific section. Enable line numbering for a specific section.
Disables the document grid so Word counts lines based on content, not grid lines.
""" """
sectPr = section._sectPr sectPr = section._sectPr
# Disable document grid to avoid Word treating a grid line as line 1
docGrid = sectPr.find(qn("w:docGrid"))
if docGrid is not None:
docGrid.set(qn("w:type"), "none")
# Create the line numbering element: <w:lnNumType> # Create the line numbering element: <w:lnNumType>
lnNumType = OxmlElement("w:lnNumType") lnNumType = OxmlElement("w:lnNumType")
lnNumType.set(qn("w:start"), str(start_at)) lnNumType.set(qn("w:start"), str(start_at))