Files
marqdo/examples/anlian-mq/components/feed.mq.md
T
cflmy 4488a3cb70 feat(migrate): M7 迁移与版本门 — per-file markup + migrate labels + 全仓迁移
原计划的"翻转默认 + 旧形硬报错"不可行:`[键](集合)` 与 `[描述](实现)` 外形相同,
翻转会让 506 处取元静默变义,硬报错又拿不到证据。改为**按文件声明**。

一、per-file markup
- frontmatter `markup: occlusion`(或 `标记: 遮蔽`)决定该文件模式
- load.rs 先取模式,用 parse::expr::with_markup(线程局部压栈)包住解析
- 同一进程可同时加载两种模式的文件(imports);MARQDO_MARKUP 仍作进程默认
- 好处:迁移逐文件、可增量、可回滚,不存在半迁移的静默错义

二、`marqdo migrate labels [--write|--json]`
改写规则:
  [键](集合)      → [键](access(集合, "键"))
  [`名`](集合)    → [名](access(集合, `名`))
  - [项](集合)    → - [项](遍历 集合 为 项)

安全模型:改写 → 重解析 → 证明等价 → 才写
- 原文件按 classic 解析得 AST-A;改写后按 occlusion 解析得 AST-B
- 反归一化 B(标签与键同名且 payload 为 access 的遮蔽还原成 Index)
- Debug(A) == Debug(反归一化(B))(抹掉行号)才写入,否则原文件一字不动

只改代码行(LineKind::Code);表格行只改 **…** 单元格,散文 markdown 链接不碰;
链式索引由内向外改写,已迁移的有守卫不二次改。

三、access 提升为宿主函数 HostFn::Access(u16 id 212)
与旧取元逐字一致(Map 按键 / List 1-based / 缺键 missing map key);
进 HostFn 是为了两个后端共用同一实现,interp 里的特例已删除。

四、顺带修的两处真实语义缺陷
1. payload 继承外层"文本模式":`f text=[k](access(c,k))` 中 access 不被当调用
   → `()` 内永远允许 callee(args)
2. 遮蔽形状判定过宽:`[问候] ([格式化] "Bo")` 误判为遮蔽
   → 要求 `]` 后紧跟 `(`,否则落回方括号调用

五、全仓迁移结果
migrate labels: 256 index, 23 loop, 80 file written;0 文件被等价性拒绝;
迁移后 cargo test --release → 604 passed / 0 failed;再跑迁移幂等。

等价性检查先后抓出 4 类改写 bug(表格散文链接、payload 文本模式、链式索引、
遮蔽与方括号调用混淆),每类都是先拦下再修工具,未污染文件。

测试:6 个单测 + 3 个集成(干跑不写盘 / 写入后运行输出不变且幂等 /
等价失败文件不动);全量 604 passed / 0 failed(M3 后 595 + 9);双后端一致。

文档:doc/design/change-m7-migration.md
2026-10-22 15:33:31 +08:00

5.6 KiB
Raw Blame History


markup: occlusion title: components/feed description: 帖子列表 / 新闻时间线 / 板块栏 HTML 片段(对齐 Django feed 与 home 局部模板)。 import table:lib/table.mq.md import text:lib/text.mq.md

帖子列表HTML

+ `行`

给定帖子行记录列表,输出 ul.home-posts-list 标记(首页与列表页共用)。

段 = None

  • [帖](遍历 行 为 帖) 板 = board) 题 = title) 链 = slug) 作 = author) 评 = comments_count) 时 = created_at)
    1. not 作 作 = "匿名"
    2. not 评 评 = 0
    3. not 时 时 = ""
    一项 = "
  • <article class="home-post-card feed-post-card"><a href="/post/" + 链 + "" class="home-post-card-link feed-post-card-link"><span class="home-post-board feed-post-board">" + 板 + "<div class="home-post-body feed-post-body"><h3 class="home-post-title feed-post-title">" + 题 + "<div class="home-post-meta feed-post-meta"><span class="home-post-meta-item feed-post-meta-item"><span class="anlian-icon anlian-icon--user" aria-hidden="true"> " + 作 + "<span class="home-post-meta-item feed-post-meta-item"><span class="anlian-icon anlian-icon--comment" aria-hidden="true"> " + 评 + "<span class="home-post-arrow feed-post-arrow" aria-hidden="true"><span class="anlian-icon anlian-icon--chevron-right">
  • " 段 = > table.append list=段 item=一项
  1. 段 内 = > text.str_join xs=段 sep="" "<ul class="home-posts-list feed-posts-list">" + 内 + ""

"<ul class="home-posts-list feed-posts-list"><li class="home-posts-empty feed-empty">暂无帖子,<a href="/post/public">去发帖"

新闻时间线HTML

+ `行`

给定新闻行记录列表,输出 .news-timeline 标记。

段 = None

  • [讯](遍历 行 为 讯) 题 = title) 链 = slug) 板 = board) 时 = created_at)
    1. not 板 板 = ""
    2. not 时 时 = ""
    一项 = "<li class="news-timeline-item"><span class="news-timeline-node" aria-hidden="true"><article class="news-timeline-card"><div class="news-timeline-meta"><time class="news-timeline-date">" + 时 + "<span class="news-timeline-board">" + 板 + "<h3 class="news-timeline-title"><a href="/news/" + 链 + "" class="news-timeline-link">" + 题 + "
  • " 段 = > table.append list=段 item=一项
  1. 段 内 = > text.str_join xs=段 sep="" "<div class="news-timeline"><div class="news-timeline-rail" aria-hidden="true"><span class="news-timeline-line"><span class="news-timeline-arrow" aria-hidden="true"><span class="anlian-icon anlian-icon--chevron-right news-timeline-arrow-icon--right"><span class="anlian-icon anlian-icon--chevron-down news-timeline-arrow-icon--down"><ol class="news-timeline-items">" + 内 + "
"
  • "<div class="news-timeline"><div class="news-timeline-rail" aria-hidden="true"><span class="news-timeline-line"><span class="news-timeline-arrow" aria-hidden="true"><ol class="news-timeline-items"><li class="news-timeline-item news-timeline-item-empty"><article class="news-timeline-card"><p class="news-timeline-empty">暂无新闻

    "

    板块栏HTML

    + `板块`
    + `前缀`
    + `查询键`
    + `全部类`
    

    板块 Tab 栏。前缀 如 /post/ten/;查询键 为 board_id 或 news_board_id;全部类 为 Tab 共用 class(含 js hook)。

    数据属 = "data-board" 全标签 = "全部"

    1. 查询键 == "news_board_id" 数据属 = "data-news-board" 全标签 = "所有板块"

    段 = None 全链 = 前缀 + "?" + 查询键 + "=0" 全项 = "<a href="" + 全链 + "" class="" + 全部类 + " active" " + 数据属 + "="0">" + 全标签 + "" 段 = > table.append list=段 item=全项

    • [板](遍历 板块 为 板) 名 = name) 号 = id) 链 = 前缀 + "?" + 查询键 + "=" + 号 项 = "<a href="" + 链 + "" class="" + 全部类 + "" " + 数据属 + "="" + 号 + "">" + 名 + "" 段 = > table.append list=段 item=项
    1. 查询键 == "news_board_id" 更多 = "<a href="/news" class="home-posts-tab home-posts-tab-more">全部新闻" 段 = > table.append list=段 item=更多

    内 = > text.str_join xs=段 sep="" 栏类 = "home-posts-board-bar"

    1. 查询键 == "news_board_id" 栏类 = "home-posts-board-bar home-news-board-bar"

    "<div class="" + 栏类 + "" data-feed-board><button type="button" class="home-posts-scroll home-posts-scroll-left" aria-label="向左滚动"><span class="anlian-icon anlian-icon--chevron-left"><div class="home-posts-segment-outer"><div class="home-posts-segment"><div class="home-posts-spotlight" aria-hidden="true"><div class="home-posts-tabs-scroll"><div class="home-posts-tabs" role="tablist">" + 内 + "<button type="button" class="home-posts-scroll home-posts-scroll-right" aria-label="向右滚动"><span class="anlian-icon anlian-icon--chevron-right">"