From f3791d11b429cbacd0b1c7c023949455f7714658 Mon Sep 17 00:00:00 2001 From: cflmy Date: Sun, 18 Oct 2026 12:17:42 +0800 Subject: [PATCH] refactor(view): evaluate cell plans through the interpreter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete the source-line table scanner. 内核表/会话表 are now evaluated as ordinary Marqdo bindings (with simple assignment dependencies) via Interpreter::capture_declarations. Every view page uses the same cell toolbar; run/watch semantics are unchanged; no new CLI or Markdown marker. --- .cursor/skills/marqdo/SKILL.md | 2 +- CHANGELOG.md | 2 +- README.md | 2 +- doc/design/notebook-session.md | 7 +- doc/design/notebook-syntax.md | 8 +- src/interp.rs | 147 +++++++++++++++++ src/notebook/mod.rs | 277 +++++++++++++++++++++------------ src/view/html.rs | 15 +- 8 files changed, 335 insertions(+), 125 deletions(-) diff --git a/.cursor/skills/marqdo/SKILL.md b/.cursor/skills/marqdo/SKILL.md index 5d926d0..04199c9 100644 --- a/.cursor/skills/marqdo/SKILL.md +++ b/.cursor/skills/marqdo/SKILL.md @@ -210,7 +210,7 @@ Design: [ext-quantum.md](../../doc/design/ext-quantum.md) · Q7: [ext-quantum-q7 - `invoke` returns a record (`ok`, `code`, `stdout`, `stderr`, `ms`, `timed_out`, `truncated`, `result`); pass `input` for JSON stdin and `output="json"` for a parsed result. - `call` is JSON-in / JSON-out; `call_many` fans out one program over a list with ordered results. - `session_open` starts a persistent Python/Node kernel; `session_eval` evaluates source; `session_set` / `session_get` bridge values explicitly as JSON. Close it with `session_close`. -- A view document can expose cells: bind `内核表` and `会话表` as ordinary tables inside `# main`. `marqdo view` adds cell stepping, Run All, kernel switching, journal and reload. There is no separate notebook CLI mode or command, and no new Markdown marker exists. +- A view document can expose cells: bind `内核表` and `会话表` as ordinary tables inside `# main`. `marqdo view` evaluates those bindings through the interpreter (`capture_declarations`), never by scanning source lines, and adds cell stepping, Run All, kernel switching, journal and reload. There is no separate notebook CLI mode or command, and no new Markdown marker exists. - The same source remains the authority; state crossing kernels is explicit, never implicitly mirrored. ## AI authoring workflow diff --git a/CHANGELOG.md b/CHANGELOG.md index 7661514..1ad3f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- **view cells 概念收敛**:`view` 是唯一交互面;只有文档声明 `内核表` / `会话表` 时才显示 cell 控件,普通 view 不显示;移除 `In []` / `Out []` 的 Jupyter 式提示与 Notebook 品牌;没有新增 notebook CLI 或第二个交互模式。 +- **view cells 概念收敛**:`view` 是唯一交互面;所有 view 页面共用同一套 cell 工具栏/布局;cell plan 由解释器 `capture_declarations` 对 `内核表` / `会话表` 求值(含简单依赖),删除源码行扫描;移除 `In []` / `Out []` 的 Jupyter 式提示与 Notebook 品牌;没有新增 CLI 或第二个交互模式。 ### Fixed ### Changed diff --git a/README.md b/README.md index 3aac1fc..c0dd789 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ marqdo catalog public -o .marqdo ## 现状(v1.5.0) -- **外联 v2 / view 交互单元(v1.5.0)**:结构化 invoke · JSON call/call_many · 并行扇出 · Python/Node 持久内核 · 显式状态桥 · cell 单步/Run All/内核切换 · 高对比浅深主题;扩展包同步 **1.5.0** +- **外联 v2 / view 交互单元(v1.5.0)**:结构化 invoke · JSON call/call_many · 并行扇出 · Python/Node 持久内核 · 显式状态桥 · cell 单步/Run All/内核切换 · 解释器求值 cell plan(无源码行扫描)· 高对比浅深主题;扩展包同步 **1.5.0** - **裸自增升参(v1.4.6)**:首次粗体赋值左值即声明;`**n = n + 1**` 无反引号也升为必选形参。扩展包仍为 **1.4.5** - **Streamable HTTP MCP + web invoke 鉴权(v1.4.5)**:`agent_mcp_serve transport=http` · Bearer/`X-Api-Key` 注入 · `unauthorized`→401 · openai/agent `json.get` 硬化 - **LLM 传输软失败 + `ext/ai` 表优先(v1.4.4)**:上游不可达 → `status=error`(不 abort);`agent`/`llm` 去 `json.set` 胶水 · [agent-llm-transport-soft-2026-10.md](doc/research/agent-llm-transport-soft-2026-10.md) diff --git a/doc/design/notebook-session.md b/doc/design/notebook-session.md index 965578e..8f826da 100644 --- a/doc/design/notebook-session.md +++ b/doc/design/notebook-session.md @@ -23,11 +23,12 @@ --- -## 1.1 实施状态(2026-10-17) +## 1.1 实施状态(2026-10-18) | 能力 | 状态 | 位置 | |---|---|---| | `内核表` / `会话表` 解析(中英列名) | ✅ | `src/notebook/mod.rs` | +| cell plan 求值 | ✅ 解释器 `capture_declarations`;不再扫描源码行 | `src/interp.rs` · `src/notebook/mod.rs` | | cell index(绑定名 / 行号 / source hash) | ✅ | 同上 | | 命名内核 + 默认内核 + 语言校验 | ✅ | 同上 | | 同内核共享 / 跨内核隔离 | ✅ | Node 金样例 + 单测 | @@ -50,7 +51,7 @@ --- -## 2. 两种执行面(不是两个 CLI 模式) +## 2. 两个执行面(不是两个 CLI 模式) ### 2.1 Program execution(规范) @@ -130,7 +131,7 @@ DocumentSession 1. 读取/解析文档(现有 `parse_source` / `load_module`)。 2. 遍历 AST,找 `Stmt::Assign { name, value: Expr::Code(c) }`。 3. 记录 name、lang、source、span、source hash。 -4. 读取 `内核表` / `会话表` 绑定(见 [notebook-syntax.md](notebook-syntax.md))。 +4. 通过解释器求值 `内核表` / `会话表` 绑定(`capture_declarations`,含简单依赖);不扫描源码行(见 [notebook-syntax.md](notebook-syntax.md))。 5. 解析 kernel 声明与 cell 归属;校验;生成诊断。 6. 生成执行顺序: - 有会话表 → 行顺序; diff --git a/doc/design/notebook-syntax.md b/doc/design/notebook-syntax.md index 1c39a7d..5ceda48 100644 --- a/doc/design/notebook-syntax.md +++ b/doc/design/notebook-syntax.md @@ -110,7 +110,7 @@ Marqdo 的选择: ````markdown # main -这份文档演示一个最小 notebook:两个 Python 单元共享 `分析` 内核, +这份文档演示一个最小 view cells 文档:两个 Python 单元共享 `分析` 内核, 一个绘图单元在隔离的 `绘图` 内核里运行。 `内核表` = @@ -211,7 +211,7 @@ print(x + 1) ## 5. 可读性规则(语法评审标准) -新增/修改任何 notebook 语法,必须满足: +新增/修改任何 cell 表约定,必须满足: 1. **先读人话**:去掉执行语义后,表格仍像目录/清单。 2. **不使用属性串**:不写 `kernel=…`、`class=…`、JSON/YAML 元数据。 @@ -243,12 +243,12 @@ print(x + 1) --- -## 7. 与 Program mode 的关系 +## 7. 与 program execution 的关系 - `内核表` / `会话表` 是**声明**,不是执行指令。 - `marqdo run` 仍然执行 `# main` 的程序语义;这两个表会被求值为普通数据。 - `run` 的外联编排用显式 API(`foreign.session_open` / `session_eval` / `call`);表只服务 `view` 的 cells 与一键 Run All。 -- 两种模式可以并存: +- 两者可以并存: - 文档用表描述“交互时怎么跑”; - `# main` 用显式调用描述“CI 时怎么跑”。 - 如果两者冲突,以 `run` 的程序语义为准;cell 表只影响 `view`。 diff --git a/src/interp.rs b/src/interp.rs index 757778b..283c47c 100644 --- a/src/interp.rs +++ b/src/interp.rs @@ -372,6 +372,98 @@ impl Interpreter { result } + /// Evaluate only the entry object's top-level assignments, without running + /// calls/returns/control flow. This is the view plan's language-native + /// projection: cell tables are ordinary Marqdo values, not source scans. + /// Evaluate selected entry bindings plus their assignment dependencies. + /// This is the view plan's language-native projection: cell tables are + /// ordinary Marqdo values, not source scans. + pub fn capture_declarations( + &mut self, + module: &Module, + names: &[&str], + ) -> Result> { + let prev = self.site_module; + self.site_module = Some(module as *const Module); + let result = (|| { + let entry = find_top(module, "main").or_else(|| { + let entries: Vec<&Function> = module + .functions + .iter() + .filter(|f| f.is_object() && f.params.is_empty()) + .collect(); + if entries.len() == 1 { + Some(entries[0]) + } else { + None + } + }); + let entry = entry.ok_or_else(|| self.err("no `# main` object to inspect"))?; + let assignments: std::collections::HashMap<&str, &Expr> = entry + .body + .iter() + .filter_map(|stmt| match stmt { + Stmt::Assign { name, value, .. } => Some((name.as_str(), value)), + _ => None, + }) + .collect(); + let mut env = Env::with_metadata(module); + let mut done = std::collections::HashSet::new(); + let mut visiting = std::collections::HashSet::new(); + + fn resolve( + this: &mut Interpreter, + module: &Module, + fun: &Function, + assignments: &std::collections::HashMap<&str, &Expr>, + name: &str, + env: &mut Env, + done: &mut std::collections::HashSet, + visiting: &mut std::collections::HashSet, + ) -> Result<()> { + if done.contains(name) { + return Ok(()); + } + if !visiting.insert(name.to_string()) { + return Err(this.err(format!("cyclic view-plan binding `{name}`"))); + } + let Some(expr) = assignments.get(name) else { + visiting.remove(name); + return Ok(()); + }; + let mut deps = std::collections::HashSet::new(); + collect_decl_reads(expr, &mut deps); + for dep in deps { + if assignments.contains_key(dep.as_str()) && env.get(&dep).is_none() { + resolve(this, module, fun, assignments, &dep, env, done, visiting)?; + } + } + let value = this.eval_expr(module, fun, env, expr)?; + env.set(name.to_string(), value); + done.insert(name.to_string()); + visiting.remove(name); + Ok(()) + } + + for name in names { + resolve( + self, + module, + entry, + &assignments, + name, + &mut env, + &mut done, + &mut visiting, + )?; + } + self.entry_bindings = env.vars_clone(); + Ok(self.entry_bindings.clone()) + })(); + self.site_module = prev; + result + } + pub fn run_module(&mut self, module: &Module) -> Result { let prev = self.site_module; self.site_module = Some(module as *const Module); @@ -1557,6 +1649,61 @@ fn bind_args( Ok(out) } +fn collect_decl_reads(expr: &Expr, out: &mut std::collections::HashSet) { + match expr { + Expr::Var(name) => { + out.insert(name.clone()); + } + Expr::Interp(parts) => { + for part in parts { + match part { + InterpPart::Var(name) => { + out.insert(name.clone()); + } + InterpPart::Index { base, .. } => { + out.insert(base.clone()); + } + InterpPart::Lit(_) => {} + } + } + } + Expr::Index { base, label } => { + collect_decl_reads(base, out); + if let IndexKey::Var(name) = label { + out.insert(name.clone()); + } + } + Expr::Binary { left, right, .. } => { + collect_decl_reads(left, out); + collect_decl_reads(right, out); + } + Expr::Unary { expr, .. } => collect_decl_reads(expr, out), + Expr::List(xs) => { + for x in xs { + collect_decl_reads(x, out); + } + } + Expr::Map(entries) => { + for (_, v) in entries { + collect_decl_reads(v, out); + } + } + Expr::Call(call) => { + if let Some(receiver) = &call.receiver { + out.insert(receiver.clone()); + } + for arg in &call.args { + match arg { + Arg::Positional(e) | Arg::Named { value: e, .. } => { + collect_decl_reads(e, out); + } + } + } + } + Expr::Literal(_) | Expr::Formula(_) | Expr::Code(_) => {} + } +} + fn find_top<'a>(module: &'a Module, name: &str) -> Option<&'a Function> { module.functions.iter().find(|f| f.name == name) } diff --git a/src/notebook/mod.rs b/src/notebook/mod.rs index 48458ed..04daf95 100644 --- a/src/notebook/mod.rs +++ b/src/notebook/mod.rs @@ -11,7 +11,6 @@ use sha2::{Digest, Sha256}; use crate::foreign::registry; use crate::host::foreign_session; use crate::host::HostContext; -use crate::parse::parse_source; use crate::value::Value; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -104,90 +103,69 @@ fn now_ms() -> i64 { .unwrap_or(0) } -/// Split a GFM row into trimmed cells. -fn split_row(line: &str) -> Vec { - let t = line.trim(); - let t = t.strip_prefix('|').unwrap_or(t); - let t = t.strip_suffix('|').unwrap_or(t); - t.split('|') - .map(|c| c.trim().trim_matches('`').trim().to_string()) - .collect() +/// Convert a table value into row maps. Handles both row tables (`| @ | ... |`) +/// and ordinary column tables; no source text is scanned. +fn table_rows(v: &Value) -> Result>, String> { + match v { + Value::None => Ok(Vec::new()), + Value::List(rows) => { + let mut out = Vec::with_capacity(rows.len()); + for (i, row) in rows.iter().enumerate() { + let Value::Map(pairs) = row else { + return Err(format!("view table row {} is not a map", i + 1)); + }; + out.push( + pairs + .iter() + .filter(|(k, _)| k != "@") + .map(|(k, v)| (k.clone(), v.clone())) + .collect(), + ); + } + Ok(out) + } + Value::Map(cols) => { + let mut width = 0usize; + for (name, value) in cols { + let Value::List(xs) = value else { + return Err(format!("view table column `{name}` is not a list")); + }; + width = width.max(xs.len()); + } + let mut out = Vec::with_capacity(width); + for i in 0..width { + let mut row = HashMap::new(); + for (name, value) in cols { + if let Value::List(xs) = value { + if let Some(v) = xs.get(i) { + row.insert(name.clone(), v.clone()); + } + } + } + out.push(row); + } + Ok(out) + } + _ => Err("view plan binding is not a table".into()), + } } -/// Find `` `name` = `` and the first contiguous table after it. -fn table_after(source: &str, name: &str) -> Result>>, String> { - let lines: Vec<&str> = source.lines().collect(); - let needle_a = format!("`{name}`"); - let needle_b = format!("{name} ="); - let mut start = None; - for (i, line) in lines.iter().enumerate() { - let t = line.trim(); - if t.starts_with(&needle_a) && t.contains('=') || t.starts_with(&needle_b) { - start = Some(i + 1); - break; - } - } - let Some(mut i) = start else { - return Ok(None); - }; - while i < lines.len() && !lines[i].trim().starts_with('|') { - if !lines[i].trim().is_empty() && !lines[i].trim().starts_with('|') { - // Prose between the binding and the table is allowed. - } - i += 1; - } - if i >= lines.len() { - return Ok(None); - } - let mut rows = Vec::new(); - let mut header: Option> = None; - while i < lines.len() { - let t = lines[i].trim(); - if !t.starts_with('|') { - break; - } - i += 1; - if t.chars().all(|c| c == '|' || c == '-' || c == ':' || c.is_whitespace()) { - continue; - } - let cells = split_row(t); - if header.is_none() { - header = Some(cells); - continue; - } - let h = header.as_ref().unwrap(); - if cells.len() != h.len() { - return Err(format!( - "table `{name}`: row has {} cells, header has {}", - cells.len(), - h.len() - )); - } - let mut row = HashMap::new(); - for (k, v) in h.iter().zip(cells) { - row.insert(k.clone(), v); - } - rows.push(row); - } - Ok(Some(rows)) -} - -fn table_any( - source: &str, +fn table_from_bindings( + bindings: &HashMap, names: &[&str], -) -> Result>>, String> { +) -> Result>>, String> { for name in names { - if let Some(rows) = table_after(source, name)? { - return Ok(Some(rows)); + if let Some(value) = bindings.get(*name) { + return table_rows(value).map(Some); } } Ok(None) } -fn col<'a>(row: &'a HashMap, names: &[&str]) -> Option<&'a String> { +fn col_value<'a>(row: &'a HashMap, names: &[&str]) -> Option<&'a Value> { for n in names { if let Some(v) = row.get(*n) { - if !v.is_empty() { + if !matches!(v, Value::None) { return Some(v); } } @@ -195,6 +173,41 @@ fn col<'a>(row: &'a HashMap, names: &[&str]) -> Option<&'a Strin None } +fn value_text(v: &Value) -> String { + match v { + Value::Text(s) => s.clone(), + Value::None => String::new(), + other => other.as_display(), + } +} + +fn col_text(row: &HashMap, names: &[&str]) -> Option { + col_value(row, names).map(value_text).filter(|s| !s.trim().is_empty()) +} + +/// Evaluate the entry object's declarations with the real interpreter. Tables +/// are ordinary Marqdo values; the view does not re-parse source text. +fn capture_bindings( + path: &Path, + root: &Path, + module: &crate::ast::Module, + source: &str, +) -> Result, String> { + let mut host = HostContext::for_capture(Some(path), crate::host::HostCaps::default()); + host.cwd = path.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(); + host.fs_root = Some(root.to_path_buf()); + host.entry_path = Some(path.to_path_buf()); + host.entry_source = Some(source.to_string()); + host.entry_metadata = module.metadata.clone(); + let mut interp = crate::interp::Interpreter::with_capture(Some(path), false).with_host(host); + interp + .capture_declarations( + module, + &["内核表", "kernels", "Kernels", "会话表", "session", "Session"], + ) + .map_err(|e| format!("view plan evaluation: {e}")) +} + fn collect_cells(stmts: &[crate::ast::Stmt], out: &mut Vec, seen: &mut HashSet) -> Result<(), String> { for stmt in stmts { match stmt { @@ -244,7 +257,12 @@ impl DocumentSession { pub fn open(path: &Path, root: &Path) -> Result { let source = std::fs::read_to_string(path) .map_err(|e| format!("read {}: {e}", path.display()))?; - let module = parse_source(&source).map_err(|e| format!("parse {}: {e}", path.display()))?; + let bind_ctx = crate::binding::BindingContext::from_binds( + &[], + crate::binding::cwd_for_path(Some(path)), + ); + let module = crate::load::load_module_with_ctx(path, &bind_ctx) + .map_err(|e| format!("load {}: {e}", path.display()))?; let entry = module .functions .iter() @@ -261,25 +279,21 @@ impl DocumentSession { let mut cells = Vec::new(); let mut seen = HashSet::new(); collect_cells(&entry.body, &mut cells, &mut seen)?; - if cells.is_empty() { - return Err("notebook: no bound code fences (`name` = + ```lang)".into()); - } + let declarations = capture_bindings(path, root, &module, &source)?; let mut kernels: Vec = Vec::new(); let mut kernel_map: HashMap = HashMap::new(); - if let Some(rows) = table_any(&source, &["内核表", "kernels", "Kernels"])? { + if let Some(rows) = table_from_bindings(&declarations, &["内核表", "kernels", "Kernels"])? { if rows.is_empty() { return Err("内核表: at least one kernel row is required".into()); } for row in rows { - let name = col(&row, &["名称", "Name", "name"]) - .ok_or_else(|| "内核表: missing 名称/Name".to_string())? - .clone(); - let lang = col(&row, &["语言", "Language", "language", "lang"]) - .ok_or_else(|| format!("内核表[{name}]: missing 语言/Language"))? - .clone(); + let name = col_text(&row, &["名称", "Name", "name"]) + .ok_or_else(|| "内核表: missing 名称/Name".to_string())?; + let lang = col_text(&row, &["语言", "Language", "language", "lang"]) + .ok_or_else(|| format!("内核表[{name}]: missing 语言/Language"))?; let lang = registry::canonical(&lang); - let cmd = col(&row, &["命令", "Command", "command", "cmd"]).cloned(); + let cmd = col_text(&row, &["命令", "Command", "command", "cmd"]); if kernel_map.contains_key(&name) { return Err(format!("内核表: kernel `{name}` is declared twice")); } @@ -295,7 +309,7 @@ impl DocumentSession { } let mut order: Vec = Vec::new(); - let session_rows = table_any(&source, &["会话表", "session", "Session"])?; + let session_rows = table_from_bindings(&declarations, &["会话表", "session", "Session"])?; if let Some(rows) = session_rows { if rows.is_empty() { return Err("会话表: at least one cell row is required".into()); @@ -307,12 +321,10 @@ impl DocumentSession { .collect(); let mut listed = HashSet::new(); for row in rows { - let cell_name = col(&row, &["单元", "Cell", "cell", "单元名"]) - .ok_or_else(|| "会话表: missing 单元/Cell".to_string())? - .clone(); - let kernel_name = col(&row, &["内核", "Kernel", "kernel"]) - .ok_or_else(|| format!("会话表[{cell_name}]: missing 内核/Kernel"))? - .clone(); + let cell_name = col_text(&row, &["单元", "Cell", "cell", "单元名"]) + .ok_or_else(|| "会话表: missing 单元/Cell".to_string())?; + let kernel_name = col_text(&row, &["内核", "Kernel", "kernel"]) + .ok_or_else(|| format!("会话表[{cell_name}]: missing 内核/Kernel"))?; let Some(&ci) = by_name.get(&cell_name) else { return Err(format!("会话表: unknown cell `{cell_name}`")); }; @@ -862,17 +874,80 @@ mod tests { use super::*; #[test] - fn rows_parse() { - assert_eq!(split_row("| a | b |"), vec!["a", "b"]); - assert_eq!(split_row("| `a` | b |"), vec!["a", "b"]); + fn table_rows_reads_row_records_and_columns() { + let row_table = Value::List(vec![Value::Map(vec![ + ("@".into(), Value::Text("1".into())), + ("名称".into(), Value::Text("分析".into())), + ("语言".into(), Value::Text("python".into())), + ])]); + let rows = table_rows(&row_table).unwrap(); + assert_eq!(rows.len(), 1); + assert_eq!(col_text(&rows[0], &["名称"]).as_deref(), Some("分析")); + + let column_table = Value::Map(vec![ + ("名称".into(), Value::List(vec![Value::Text("分析".into())])), + ("语言".into(), Value::List(vec![Value::Text("python".into())])), + ]); + let rows = table_rows(&column_table).unwrap(); + assert_eq!(rows.len(), 1); + assert_eq!(col_text(&rows[0], &["语言"]).as_deref(), Some("python")); } #[test] - fn table_after_finds_rows() { - let src = "# main\n\n`内核表` =\n\n| 名称 | 语言 |\n|---|---|\n| 分析 | python |\n"; - let rows = table_after(src, "内核表").unwrap().unwrap(); - assert_eq!(rows.len(), 1); - assert_eq!(rows[0].get("名称").map(|s| s.as_str()), Some("分析")); + fn plan_uses_evaluated_bindings() { + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let path = root.join(format!( + "target/view-plan-{}-{}.mq.md", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0) + )); + let source = r#"# main + +`lang` = python + +`内核表` = + +| @ | 名称 | 语言 | +|---|------|------| +| 1 | 分析 | `lang` | + +`会话表` = + +| @ | 单元 | 内核 | +|---|------|------| +| 1 | 单元 | 分析 | + +`单元` = +```python +print(1) +``` +"#; + std::fs::write(&path, source).unwrap(); + let s = DocumentSession::open(&path, &root).unwrap(); + assert_eq!(s.cells.len(), 1); + assert_eq!(s.cells[0].kernel, "分析"); + assert_eq!(s.kernels[0].lang, "python"); + let _ = std::fs::remove_file(&path); + } + + #[test] + fn view_open_accepts_a_document_without_cells() { + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let path = root.join(format!( + "target/view-empty-{}-{}.mq.md", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_nanos()) + .unwrap_or(0) + )); + std::fs::write(&path, "# main\n\n> print text=hello\n").unwrap(); + let s = DocumentSession::open(&path, &root).unwrap(); + assert!(s.cells.is_empty()); + let _ = std::fs::remove_file(&path); } fn node_available() -> bool { diff --git a/src/view/html.rs b/src/view/html.rs index f108c0a..154cda0 100644 --- a/src/view/html.rs +++ b/src/view/html.rs @@ -2870,13 +2870,6 @@ pub fn page_index(files: &[PathBuf], only: Option<&Path>, links: &LinkMode) -> S layout("index", &nav, &main) } -/// True only when the document declares a cell table; ordinary view pages stay classic. -fn has_cell_tables(source: &str) -> bool { - ["`内核表`", "`会话表`", "`kernels`", "`session`"] - .iter() - .any(|needle| source.contains(needle)) -} - fn notebook_ui() -> &'static str { r#"