ForcePilot/backend/package/yuxi/channel/extensions/github/format.py
Kris 702fcd4c33 feat(github): 新增GitHub渠道插件完整实现
新增了完整的GitHub集成插件,包含认证、会话管理、Webhook处理、消息收发、反应支持等核心功能,支持Issues、Discussions、Pull Request的交互与通知。
2026-05-21 10:48:42 +08:00

32 lines
786 B
Python

from __future__ import annotations
def sanitize_gfm_text(text: str) -> str:
return text.replace("\x00", "")
def chunk_gfm_markdown(text: str, limit: int = 65000) -> list[str]:
if len(text) <= limit:
return [text]
chunks: list[str] = []
in_code_block = False
current = ""
for line in text.split("\n"):
stripped = line.strip()
if stripped.startswith("```"):
in_code_block = not in_code_block
candidate = current + line + "\n"
if len(candidate) > limit and not in_code_block:
chunks.append(current.rstrip())
current = line + "\n"
else:
current = candidate
if current.strip():
chunks.append(current.rstrip())
return chunks if chunks else [text]