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())