fix(telegram): hard-cut when fence body cut lands on the prefix

A leading space in the fenced body made the soft cut land at min_code_pos
and re-emit the same fence forever. Require progress past the fence line.
This commit is contained in:
santhreal authored and chengyongru committed 2026-07-23 23:56:18 +08:00
1 parent 98d661775e
commit 7e9426d9bd
2 files changed
+19 -2

No files matched your search

+6 -2
View File
@@ -102,7 +102,7 @@ def _split_telegram_markdown(content: str, max_len: int) -> list[str]:
adjusted = recut.rfind("\n", min_code_pos)
if adjusted < min_code_pos:
adjusted = recut.rfind(" ", min_code_pos)
pos = adjusted if adjusted >= min_code_pos else budget
pos = adjusted if adjusted > min_code_pos else budget
elif pos + len(closing) > max_len:
budget = max_len - len(closing)
if budget <= min_code_pos:
@@ -113,7 +113,11 @@ def _split_telegram_markdown(content: str, max_len: int) -> list[str]:
adjusted = recut.rfind("\n", min_code_pos)
if adjusted < min_code_pos:
adjusted = recut.rfind(" ", min_code_pos)
pos = adjusted if adjusted >= min_code_pos else budget
pos = adjusted if adjusted > min_code_pos else budget
if pos <= min_code_pos:
chunks.append(content[:max_len])
content = content[max_len:].lstrip()
continue
chunks.append(content[:pos] + closing)
remainder = content[pos:]
if remainder.startswith("\n"):