From 670c6d3e2b2ebbed1adc6aa1504b65ee3a6789c0 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 16 Jun 2026 19:09:26 +0000 Subject: [PATCH] Fix first-page line numbering off-by-one in transcript DOCX - 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. --- scraibe/email_sender.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scraibe/email_sender.py b/scraibe/email_sender.py index d55d789..bed38b5 100644 --- a/scraibe/email_sender.py +++ b/scraibe/email_sender.py @@ -318,7 +318,7 @@ def _create_transcript_section_properties(section): - Margins: 1 inch all sides - Single column layout - 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 @@ -341,10 +341,13 @@ def _create_transcript_section_properties(section): _set_element_attr(cols, "num", "1") _set_element_attr(cols, "space", "720") - # Disable document grid to avoid Word counting phantom grid lines - docGrid = sectPr.find(f"{{{W_NS}}}docGrid") - if docGrid is not None: - _set_element_attr(docGrid, "type", "none") + # Remove document grid entirely to avoid phantom grid-based line numbering + for docGrid in sectPr.findall(f"{{{W_NS}}}docGrid"): + sectPr.remove(docGrid) + + # 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 lnNumType = OxmlElement("w:lnNumType")