From 2f9299389b4acf2fdb7872e9f19cb81a8b990878 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 14 Jun 2026 22:25:26 +0000 Subject: [PATCH] Fix line numbering: only transcript pages; ensure page numbering fields are set correctly --- scraibe/email_sender.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/scraibe/email_sender.py b/scraibe/email_sender.py index b1c7dfe..4fef17e 100644 --- a/scraibe/email_sender.py +++ b/scraibe/email_sender.py @@ -291,6 +291,29 @@ def send_email( raise EmailError(f"Failed to send email: {e}") +def _remove_line_numbering(section): + """ + Explicitly remove line numbering from a section. + """ + sectPr = section._sectPr + lnNumType = sectPr.find(qn("w:lnNumType")) + if lnNumType is not None: + sectPr.remove(lnNumType) + + +def _enable_line_numbering(section): + """ + Enable continuous line numbering for a section. + """ + sectPr = section._sectPr + lnNumType = sectPr.find(qn("w:lnNumType")) + if lnNumType is None: + lnNumType = OxmlElement("w:lnNumType") + sectPr.append(lnNumType) + lnNumType.set(qn("w:start"), "continuous") + lnNumType.set(qn("w:countBy"), "1") + + def _setup_docx_style(doc, enable_line_numbering=False): """ Base document setup (margins, font, footer). @@ -304,13 +327,9 @@ def _setup_docx_style(doc, enable_line_numbering=False): # Line numbering (only for transcript sections) if enable_line_numbering: - sectPr = section._sectPr - lnNumType = sectPr.find(qn("w:lnNumType")) - if lnNumType is None: - lnNumType = OxmlElement("w:lnNumType") - sectPr.append(lnNumType) - lnNumType.set(qn("w:start"), "continuous") - lnNumType.set(qn("w:countBy"), "1") + _enable_line_numbering(section) + else: + _remove_line_numbering(section) # Default font style = doc.styles["Normal"] @@ -583,13 +602,7 @@ def create_combined_docx( section_transcript.bottom_margin = Inches(1.0) # Enable line numbering in transcript section - sectPr = section_transcript._sectPr - lnNumType = sectPr.find(qn("w:lnNumType")) - if lnNumType is None: - lnNumType = OxmlElement("w:lnNumType") - sectPr.append(lnNumType) - lnNumType.set(qn("w:start"), "continuous") - lnNumType.set(qn("w:countBy"), "1") + _enable_line_numbering(section_transcript) # 5) Transcript content (with line numbering) _add_transcript_content(doc, transcript_text)