Translate markdown headings to WYSIWYG styles in summary .docx
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

This commit is contained in:
admin
2026-06-14 21:18:42 +00:00
parent 11e5309a8e
commit efb34dd9ff
+39 -2
View File
@@ -365,6 +365,11 @@ def create_transcript_docx(text: str, filename: str):
def create_summary_docx(text: str, filename: str): def create_summary_docx(text: str, filename: str):
""" """
Create a .docx summary with consistent font. Create a .docx summary with consistent font.
Translates markdown headings into WYSIWYG formatting:
- First heading: bold
- Second heading: italic
- Third heading: underline
- Fourth heading: italic + underline
No section headings; use bold/underline only. No section headings; use bold/underline only.
""" """
doc = Document() doc = Document()
@@ -373,8 +378,40 @@ def create_summary_docx(text: str, filename: str):
font.name = "Courier" font.name = "Courier"
font.size = Pt(12) font.size = Pt(12)
heading_count = 0 # track headings in order
for line in text.splitlines(): for line in text.splitlines():
p = doc.add_paragraph(line) stripped = line.strip()
p.paragraph_format.space_after = Pt(4) if not stripped:
continue
# Detect markdown-style headings: #, ##, ###, ####
m = re.match(r"^(#{1,4})\s+(.*)", stripped)
if m:
heading_count += 1
level = len(m.group(1)) # 1..4
content = m.group(2).strip()
p = doc.add_paragraph()
p.paragraph_format.space_after = Pt(4)
run = p.add_run(content)
run.font.name = "Courier"
run.font.size = Pt(12)
# Apply formatting based on this heading's ordinal position
if heading_count == 1:
run.bold = True
elif heading_count == 2:
run.italic = True
elif heading_count == 3:
run.underline = True
elif heading_count >= 4:
run.italic = True
run.underline = True
else:
# Normal text line
p = doc.add_paragraph(stripped)
p.paragraph_format.space_after = Pt(4)
doc.save(filename) doc.save(filename)