docs(view): recommend static snapshots and writeback persistence

Add a persistence recommendation to the user-facing foreign walkthrough: static export for published snapshots, and lib/writeback for opt-in result slots in the .mq.md source. Show a readable code-fence based writeback example.
This commit is contained in:
cflmy committed 2026-10-18 13:40:44 +08:00
1 parent 2a13e52981
commit 8dcd69412f
2 files changed
+46

No files matched your search

@@ -145,6 +145,29 @@ print(json.dumps({
`查看` consumes the `会话` handle. Run All runs `计算` in the `分析` kernel and `复核` in the `复核` kernel; the static export runs the same cells and embeds their real outputs.
---
Persisting results: two complementary options.
The static export is the publishing snapshot. `marqdo view output` runs the cells and embeds their outputs in HTML; it does not mutate the source. Use it for user docs, reviews and links.
Writeback is for living reports. Pair `foreign` with `lib/writeback` when the source should retain the latest result:
```text
import writeback:lib/writeback.mq.md
`写回代码` =
```python
print(950)
```
**结果 = > foreign.run code=`写回代码`**
**> writeback.record value=`结果` key="total"**
```
`writeback.record` writes an explicit `<!-- marqdo-out total ... -->` slot adjacent to the call. Keyed slots do not overwrite each other, and the slot can be reviewed and committed with the source. This is opt-in; it is not hidden kernel serialization.
Recommended split: static export for published user documentation; writeback for exploratory or audit documents that must keep the latest run result in the `.mq.md` itself.
The important language point:
The `初始值` table passes the same Marqdo `订单` value into both kernels. Kernel state lives in `foreign`. View only renders the handle and its cells. `run` still executes the same document as a program.
@@ -145,6 +145,29 @@ print(json.dumps({
`查看` 消费 `会话` 句柄。Run All 在 `分析` 内核执行 `计算`,在 `复核` 内核执行 `复核`;静态导出走同一批单元,并把真实输出嵌入页面。
---
执行结果持久化:两种互补方式。
静态导出是发布快照。`marqdo view output` 执行单元并把输出嵌入 HTML,不修改源码;适合用户文档、评审和链接分享。
自写回用于“活文档”。需要把最新结果留在源码里时,把 `外联` 和 `lib/writeback` 搭配使用:
```text
import writeback:lib/writeback.mq.md
`写回代码` =
```python
print(950)
```
**结果 = > 外联.运行 代码=`写回代码`**
**> writeback.record value=`结果` key="total"**
```
`writeback.record` 会在调用点附近写入显式的 `<!-- marqdo-out total ... -->` 槽位;带 key 的槽位不会互相覆盖,可以随源码一起审阅和提交。这是显式动作,不是隐藏的内核序列化。
建议分工:面向用户的发布文档用静态导出;需要保留最新执行结果的探索/审计文档用自写回,把结果写进 `.mq.md` 便于跟踪。
语言上的重点:
`初始值` 表把同一个 Marqdo `订单` 值传给两个内核。内核态归 `外联` 管理。view 只渲染句柄和单元。`run` 仍然把同一份文档当程序执行。