| 2546 | |
| 2547 | |
| 2548 | def fmt_blocks(data: dict): |
| 2549 | print(f"文档: {data.get('doc_path', '?')}") |
| 2550 | print(f"字符: {data.get('doc_chars', 0)} | Block: {data.get('block_count', 0)}") |
| 2551 | by_kind = data.get("by_kind", {}) or {} |
| 2552 | if by_kind: |
| 2553 | kind_order = ["heading", "paragraph", "list", "blockquote", "table", "code", "figure"] |
| 2554 | parts = [f"{k} {by_kind[k]}" for k in kind_order if k in by_kind] |
| 2555 | print("类型分布: " + " · ".join(parts)) |
| 2556 | print() |
| 2557 | for i, b in enumerate(data.get("blocks", []), 1): |
| 2558 | anchor = b.get("anchor") or "(no-anchor)" |
| 2559 | kind = b.get("kind", "?") |
| 2560 | if kind == "heading": |
| 2561 | tag = f"H{b.get('level', '?')}" |
| 2562 | title = b.get("title", "") |
| 2563 | summary = b.get("agent_summary") or "(无摘要)" |
| 2564 | print(f"#{i:3} [{tag:5}] ^{anchor:25} {title} ({b.get('char_count', 0)} 字符)") |
| 2565 | print(f" └─ {summary[:120]}") |
| 2566 | else: |
| 2567 | owner = b.get("owning_section_anchor") or "-" |
| 2568 | print(f"#{i:3} [{kind:10}] ^{anchor:25} ↳ ^{owner} line {b.get('line_start')} ({b.get('char_count', 0)} 字符)") |
| 2569 | preview = b.get("preview", "") |
| 2570 | if preview: |
| 2571 | print(f" {preview}") |
| 2572 | print() |
| 2573 | |
| 2574 | |
| 2575 | def fmt_find_anchor(results: list[dict]): |