Ensure first visual line respects 58-char limit including label
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

- Trim first line at word boundary if label + content > 58.
- Subsequent lines continue at full width.
This commit is contained in:
admin
2026-06-16 19:26:30 +00:00
parent 1265a664cd
commit e7aa5ebf25
+19 -4
View File
@@ -496,13 +496,28 @@ def create_transcript_docx(text: str, filename: str):
if current:
content_lines.append(current)
# First visual line: include label if present
# First visual line: include label if present, ensuring total <= max_chars
if content_lines:
first_line_text = (label_text + " " if label_text else "") + content_lines[0]
first_content = content_lines.pop(0)
if label_text:
prefix = label_text + " "
# If too long, trim first_content at word boundary
if len(prefix) + len(first_content) > max_chars:
allowed = max_chars - len(prefix)
if allowed < 1:
allowed = 1
# Truncate at word boundary
candidate = first_content[:allowed]
last_space = candidate.rfind(" ")
if last_space > 0:
candidate = candidate[:last_space]
first_content = candidate
first_line_text = prefix + first_content
else:
first_line_text = first_content
line_number += 1
_add_transcript_paragraph(doc, first_line_text, line_number=line_number)
# Remove remaining content lines' leading content (already done) from first line
content_lines = content_lines[1:]
# Subsequent visual lines: no label, just content
for cl in content_lines: