INNER CODE UNIT · Python

parse_elements

kangarooking/cangjie-skill · scripts/build_chunks.py:38

def parse_elements(text: str) -> list[dict]:
    """把 Markdown/TXT 解析为 SourceDocument elements(标题/段落/列表/代码)。"""
    elements: list[dict] = []
    heading_stack: list[tuple[int, str]] = []
    in_code = False
    buf: list[str] = []
    buf_type = "paragraph"

    def flush():
        nonlocal buf, buf_type
        content = "\n".join(buf).strip()
        buf = []
        if not content:
            return
        elements.append({
            "element_id": f"el-{len(elements):06d}",
            "type": buf_type,
            "text": content,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…