Ensure first visual line respects 58-char limit including label
- Trim first line at word boundary if label + content > 58. - Subsequent lines continue at full width.
This commit is contained in:
+19
-4
@@ -496,13 +496,28 @@ def create_transcript_docx(text: str, filename: str):
|
|||||||
if current:
|
if current:
|
||||||
content_lines.append(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:
|
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
|
line_number += 1
|
||||||
_add_transcript_paragraph(doc, first_line_text, line_number=line_number)
|
_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
|
# Subsequent visual lines: no label, just content
|
||||||
for cl in content_lines:
|
for cl in content_lines:
|
||||||
|
|||||||
Reference in New Issue
Block a user