From d0896ef10e64d2f9f04fe8086926df93266e5ec7 Mon Sep 17 00:00:00 2001 From: Yuzhiran Dev Date: Wed, 3 Jun 2026 13:13:19 +0800 Subject: [PATCH] fix: _wrap_chinese crash on mixed-width punctuation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _image_generator.py _wrap_chinese 当标题中只有 ASCII 标点 (如 ( ) ?) 而无全角标点时,max() 收到空序列崩溃。 修复:try-except 兜底 + 补充 ASCII 标点到断点列表 --- scripts/image_generator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/image_generator.py b/scripts/image_generator.py index 198aba5..bd31443 100644 --- a/scripts/image_generator.py +++ b/scripts/image_generator.py @@ -109,7 +109,10 @@ def _wrap_chinese(text: str, chars_per_line: int = 14) -> List[str]: while len(remainder) > chars_per_line: chunk = remainder[:chars_per_line] # 尝试在最后一个标点处断开 - cut = max(chunk.rfind(c) + 1 for c in (",", "、", "。", "!", "?", ":", ";", ")", " ", "—") if c in chunk[:-1]) + try: + cut = max(chunk.rfind(c) + 1 for c in (",", "、", "。", "!", "?", ":", ";", ")", " ", "—", ",", ".", "!", "?", ":", ";", ")", "(", "-") if c in chunk[:-1]) + except ValueError: + cut = 0 if cut <= 0: cut = chars_per_line lines.append(remainder[:cut].strip())