fix: _wrap_chinese crash on mixed-width punctuation
_image_generator.py _wrap_chinese 当标题中只有 ASCII 标点 (如 ( ) ?) 而无全角标点时,max() 收到空序列崩溃。 修复:try-except 兜底 + 补充 ASCII 标点到断点列表
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user