feat(PR-02): DocumentModel, Analysis v2 projection, single renderer and Live browsing
- document.rs: comrak marqdo.md.v1 parse -> DocBlock/Inline with exact UTF-8 spans - semantic.rs: typed Analysis v2 validation (schema/profile/root_id/source_digest, units/functions/statements/resources/imports/references/calls/diagnostics, per-span UTF-8 checks with explicit view.source_span_invalid warnings) - presentation.rs: one PresentationModel/Outline with source status matrix - render.rs: one ReaderRenderer; sanitized GFM, statement anchors, heading mode badges (display-only prefix strip), source pane, docs/Live|Static link policy, CSP meta, no inline scripts, no raw HTML execution - server.rs: loopback-only Live reader with Host/DNS-rebinding checks, strict percent decoding, project path boundary, security headers, read-only APIs - app.rs: AppContext degradation (core missing -> prose-only, check error -> diagnostics + revoked semantics, protocol mismatch -> hard error) - assets: single reader.css/reader.js + embedded SHA-256 AssetBundle, copied legacy logo/blossom/feather with provenance - examples + frozen-CLI Analysis goldens + rendering/HTTP/asset/no-coupling tests - ADR-0003 heading prefix/anchor identity; docs updated
This commit is contained in:
1 parent
8ba20a5c67
commit
80ce564f09
47 files changed
+26127
-203
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# ADR-0003:显示层标题前缀剥离与文档内锚点身份
|
||||
|
||||
- 状态:Accepted
|
||||
- 日期:2026-11-22
|
||||
- 关联:RFC-VIEW-0001 §5.2、§8.2、§8.3;PR-02
|
||||
|
||||
## 背景
|
||||
|
||||
`@exec` / `@knowledge` 是标题语义声明,但 Markdown 标题的**显示文本**不应把声明前缀当作正文主标题重复展示。与此同时,语义标注必须能稳定指向源码位置,而且不能在标题重名时产生重复 DOM id。Analysis v2 公开字段中:
|
||||
|
||||
- `units[]` 没有单独的“本标题的 mode”字段(RFC §4.3 已警告不得把 `kind=section` 当成 Exec/Knowledge);
|
||||
- `functions[].heading_span` 与 `units[].span` 对 ATX 标题精确对应,可作为锚点来源;
|
||||
- 继承模式无法从公开 JSON 直接读出。
|
||||
|
||||
## 决策
|
||||
|
||||
1. **标题前缀只在显示层剥离**:仅当标题文本以精确的 `@exec ` 或 `@knowledge ` 开头,且剥离后的空白折叠结果等于 Analysis `units[].name` 时,才视为合法声明并剥离;同时输出 `mq-mode-badge`。`@Exec`、拼写变体、`**@exec**` 等一律原样显示(Core 会给出诊断)。Source 态永远显示原始字节,因此剥离是可逆的显示规则,不是改写源文件。
|
||||
2. **不猜测继承模式**:没有显式声明前缀的 H3–H6 不渲染 EXEC/KNOWLEDGE 徽标,`data-semantic="document"`;H2 function 由 `functions[]` 精确映射为 `exec`,H2 knowledge 由 `units[].kind=knowledge` 映射为 `knowledge`。
|
||||
3. **锚点 id 来自源码 span**:`id="mq-h-<start-hex>-<end-hex>"`,由标题自身的 UTF-8 半开区间派生;函数大纲使用同一条 `heading_span`,保证“函数列表跳转”与正文标题命中同一个 id。禁止用标题文本、序号或随机数生成 id(重名会跳错)。
|
||||
4. **语义装饰锚点 id** 使用 RFC §8.3 的 `sha256(module_id + "\0" + start + ":" + end + ":" + kind)[0..16]`;它只在本页 DOM 内有效,不跨编辑/跨运行复用。
|
||||
5. 任何无法通过 `SourceIndex` 验证的 span(越界、非 UTF-8 边界)直接丢弃该条装饰并产生 `view.source_span_invalid` 警告,绝不把它吸附到相邻文字。
|
||||
|
||||
## 后果
|
||||
|
||||
- 同页多个 H2/H3 永远得到不同 id;`tests/rendering.rs::semantic_annotations_come_from_analysis_and_are_unique` 断言唯一性。
|
||||
- Setext 标题没有合法前缀声明,会被原样显示并沿用自身 span 锚点;如果未来需要更精确的继承模式标注,必须通过新的公开协议字段实现,不能在 JS/CSS 里猜。
|
||||
- 标题显示与源码态自动保持一致;无需额外“复制原文”逻辑。
|
||||
+6
-3
@@ -22,8 +22,8 @@
|
||||
|---|---|---|
|
||||
| PR-00 基线与旧 View 取证 | **完成** | `docs/audits/legacy-render-paths.md`、`docs/design/visual-tokens.md`、`docs/design/state-matrix.md`、ADR-0001/0002 |
|
||||
| PR-01 Tool v1 安装闭环 | **完成** | `tool.json`、`tools/package.sh`、`tools/install-smoke.sh`、`tests/core_contract.rs`、`tests/no_coupling.rs` |
|
||||
| PR-02 DocumentModel + Analysis v2 浏览 | 未开始 | — |
|
||||
| PR-03 Reader 视觉重建 | 未开始 | — |
|
||||
| PR-02 DocumentModel + Analysis v2 浏览 | **完成** | `src/document.rs`、`src/semantic.rs`、`src/presentation.rs`、`src/render.rs`、`src/server.rs`、`tests/rendering.rs`、`tests/http_live.rs`、`tests/golden/analysis-v2/`(冻结 CLI 生成) |
|
||||
| PR-03 Reader 视觉重建 | 进行中(基础主题已就绪) | `assets/reader.css`/`assets/reader.js` 单一入口,`tests/asset_integrity.rs`;完整欢迎页/响应式截图待补 |
|
||||
| PR-04 Trace v2 运行可视化 | 未开始 | — |
|
||||
| PR-05 Live 安全 + 静态导出 | 未开始 | — |
|
||||
| PR-06 冻结 CLI 端到端验收 | 未开始 | — |
|
||||
@@ -31,7 +31,10 @@
|
||||
## 证据与限制
|
||||
|
||||
- 旧 View 运行时状态:`LEGACY_RUNTIME_UNVERIFIED`(旧仓库无预编译产物,且任务禁止修改/编译旧仓库;只做只读静态审计)。
|
||||
- PR-01 起 `marqdo view --help/--version/verify` 由本程序提供;`browse`/`export` 仍返回 `view.unsupported`(PR-02/PR-05 落地)。
|
||||
- PR-01 起 `marqdo view --help/--version/verify` 由本程序提供;PR-02 起 `marqdo view [PATH]` 提供本机只读浏览。
|
||||
- `export` 仍返回 `view.unsupported`(PR-05 落地);运行入口仍显式“未启用”(PR-04)。
|
||||
- 冻结 CLI 安装烟测通过前不得声称 Tool v1 闭环可用;证据由 `tools/install-smoke.sh` 生成。
|
||||
- PR-02 的 Analysis golden 全部由冻结 CLI `check --emit` 生成(见 `tests/golden/README.md`);`examples/diagnostics` 故意 check 失败且没有 golden。
|
||||
- 已知限制:运行/变量值/内存/证明状态仍不可用且标为 UNSUPPORTED;`export` 未实现;浏览器截图验收在 PR-06。
|
||||
- 已核对旧视觉资产许可(旧仓库 Apache-2.0):logo/blossom/feather 可复用,KaTeX 不引入。
|
||||
- 已知非目标:变量运行值、内存快照、调试器、Prove/Knowledge/Lint 引擎(均标 `UNSUPPORTED`)。
|
||||
Reference in new issue
Block a user