Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions gateway/platforms/weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,20 +758,15 @@ def _pack_markdown_blocks_for_weixin(content: str, max_length: int) -> List[str]
def _split_text_for_weixin_delivery(content: str, max_length: int) -> List[str]:
"""Split content into sequential Weixin messages.

Prefer one message per top-level line/markdown unit when the author used
explicit line breaks. Oversized units fall back to block-aware packing so
long code fences still split safely.
Only split when content exceeds max_length. Keep everything in a single
message whenever possible for better readability in WeChat.
Oversized content falls back to block-aware packing so long code fences
still split safely.
"""
if len(content) <= max_length and "\n" not in content:
if len(content) <= max_length:
return [content]

chunks: List[str] = []
for unit in _split_delivery_units_for_weixin(content):
if len(unit) <= max_length:
chunks.append(unit)
continue
chunks.extend(_pack_markdown_blocks_for_weixin(unit, max_length))
return chunks or [content]
return _pack_markdown_blocks_for_weixin(content, max_length) or [content]


def _extract_text(item_list: List[Dict[str, Any]]) -> str:
Expand Down