diff --git a/mobile/index.html b/mobile/index.html index c9d208e..8da88dc 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -4698,9 +4698,14 @@ function chartMd(lines) { // ```stats: ↑/+ green, ↓/− red. The same rule as src/pages.rs stat_trend: + − - count only with // something right after them (「-12%」 is down; a lone 「-」 is "no data", 「- 待補」 is neutral). const trend = (t) => /^\s*(↑|\+(?=\S))/.test(t) ? " up" : /^\s*(↓|[−-](?=\S))/.test(t) ? " dn" : ""; -function pageMd(text, id, rev) { +// (ctr: the page's diagrams numbered as the brain numbers them — every ```mermaid in order, one +// indented under a list item too; one in a quote isn't, and is drawn here from its words. Each +// part used to count from 0 again: a diagram under a list item showed the page's first one, and +// every one after it the one before. Not yet: a ```mermaid inside ```details — this page ends the +// details at its first ``` line, the brain counts it.) +function pageMd(text, id, rev, ctr) { const L = String(text || "").replace(/\r/g, "").split("\n"); - const out = []; let i = 0, chart = 0; + const out = [], c = ctr || {n: 0}; let i = 0; const cells = (l) => l.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim()); while (i < L.length) { const l = L[i], t = l.trim(); @@ -4710,7 +4715,7 @@ function pageMd(text, id, rev) { const lang = fence[1].toLowerCase(); const body = []; i++; while (i < L.length && !L[i].trim().startsWith("```")) body.push(L[i++]); i++; - if (lang === "mermaid" && id) { out.push(`
${pageMd(q.join("\n"), id, rev)}`); + out.push(`
${pageMd(q.join("\n"), 0, 0)}`); continue; } if (/^([-*+•]|\d+[.)])\s+/.test(t)) { @@ -4777,7 +4782,7 @@ function pageMd(text, id, rev) { const words = task ? `${task[1] === " " ? "☐" : "☑"} ${inl(task[2])}` : inl(head); const lines = under.filter((x) => x.trim()), cut = Math.min(...lines.map(indent)); const plain = lines.length === under.length && lines.every((x) => !/^(#{1,6}\s|```|>|\||([-*+•]|\d+[.)])\s)/.test(x.trim())); - const inner = !lines.length ? "" : plain ? lines.map((x) => "
結論
"); check("一般段落不受影響", pageMd("第一行\n第二行\n\n第二段"), "第一行
第二行
第二段
"); +// 頁面的圖照大腦的編號:清單底下縮排的也算;引用裡的大腦不算,手機自己畫。 +const charts = (h) => [...h.matchAll(/chart\/(\d+)|data-mermaid="([^"]*)"/g)].map((x) => x[1] !== undefined ? "#" + x[1] : "畫:" + x[2]).join(" "); +check("清單底下的圖:編號接著算", charts(pageMd("```mermaid\nA\n```\n\n1. 步驟:\n ```mermaid\n B\n ```\n\n```mermaid\nC\n```", 5, 0)), "#0 #1 #2"); +check("details 後面的圖:照常從 0", charts(pageMd("```details 更多\n說明\n```\n```mermaid\nC\n```", 5, 0)), "#0"); +check("多層清單裡的圖:編號接著算", charts(pageMd("1. 甲\n ```mermaid\n A\n ```\n - 乙\n ```mermaid\n B\n ```\n2. 丙\n\n```mermaid\nC\n```", 5, 0)), "#0 #1 #2"); +check("引用裡的圖:不佔編號、手機自己畫", charts(pageMd("> ```mermaid\n> Q\n> ```\n\n```mermaid\nC\n```", 5, 0)), "畫:Q #0"); +// 項目底下沒收尾的程式碼:只到這一點為止,後面的段落和標題不被吞成程式碼。 +{ + const h = pageMd("- 執行:\n ```bash\n npm install\n\n後面的段落\n\n## 標題"); + check("項目底下沒收尾的程式碼:不吞後面的", `${h.includes("npm install後面的段落
")}|${h.lastIndexOf("標題") > h.lastIndexOf("")}`, "true|true"); +} + if (failed) process.exitCode = 1; diff --git a/src/remote.rs b/src/remote.rs index 6f2cf42..bb45c97 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -3753,7 +3753,7 @@ mod tests { }; let text = String::from_utf8_lossy(&out.stdout); assert!(out.status.success() && !text.contains("FAIL"), "{text}{}", String::from_utf8_lossy(&out.stderr)); - assert!(text.matches("OK").count() >= 12, "{text}"); + assert!(text.matches("OK").count() >= 17, "{text}"); } use super::*;