MCPcopy Create free account
hub / github.com/Qinbf/groundmap / _clean_preview

Function _clean_preview

scripts/section_parser.py:222–245  ·  view source on GitHub ↗

从段落原文提取干净的预览文字:去 markdown 标记、压空白、截 200 字。

(text: str)

Source from the content-addressed store, hash-verified

220
221
222def _clean_preview(text: str) -> str:
223 """从段落原文提取干净的预览文字:去 markdown 标记、压空白、截 200 字。"""
224 s = _strip_anchor_from_text(text)
225 # 去常见 inline markdown 标记
226 s = re.sub(r"`+([^`]+)`+", r"\1", s)
227 s = re.sub(r"\*\*([^*]+)\*\*", r"\1", s)
228 s = re.sub(r"\*([^*]+)\*", r"\1", s)
229 s = re.sub(r"__([^_]+)__", r"\1", s)
230 s = re.sub(r"_([^_]+)_", r"\1", s)
231 s = re.sub(r"~~([^~]+)~~", r"\1", s)
232 # 链接 / 图片 → 取文字部分
233 s = re.sub(r"!\[([^\]]*)\]\([^\)]*\)", r"\1", s)
234 s = re.sub(r"\[([^\]]+)\]\([^\)]*\)", r"\1", s)
235 # 双链
236 s = re.sub(r"\[\[([^\]|#]+)(?:#[^\]|]+)?(?:\|([^\]]+))?\]\]", r"\1", s)
237 # 列表 / 引用 / heading 前缀
238 s = re.sub(r"^\s*(?:[-*+]|\d+\.)\s+", "", s, flags=re.MULTILINE)
239 s = re.sub(r"^\s*>\s?", "", s, flags=re.MULTILINE)
240 s = re.sub(r"^\s*#{1,6}\s+", "", s, flags=re.MULTILINE)
241 # 压缩空白
242 s = re.sub(r"\s+", " ", s).strip()
243 if len(s) > 200:
244 s = s[:200]
245 return s
246
247
248def build_outline(blocks: list[Block], total_chars: int) -> dict:

Callers 1

build_outlineFunction · 0.85

Calls 1

_strip_anchor_from_textFunction · 0.85

Tested by

no test coverage detected