// 手機的 Markdown 清單(mobile/index.html 的 pageMd,聊天和頁面都用它):照 Markdown 的讀法—— // 空一行再接同一種項目還是同一個清單(以前每一點各自成一個清單,每一點都是「1.」,11/23),編號從 // 第一點寫的數字起,縮排在項目底下的是那一點的(續行或子清單,以前子項目被攤平成同一層、一起編號)。 import { readFileSync } from "node:fs"; const page = readFileSync(new URL("./index.html", import.meta.url), "utf8"); const at = page.indexOf("function pageMd("); if (at < 0) throw new Error("index.html 裡沒有 pageMd"); const src = page.slice(at, page.indexOf("\n}\n", at) + 2); const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]); const pageMd = new Function("inl", "esc", `${src}\nreturn pageMd;`)(esc, esc); let failed = 0; const check = (what, got, want) => { if (got === want) console.log(`OK ${what}`); else { failed++; console.log(`FAIL ${what}:\n 得到 ${got}\n 應該 ${want}`); } }; check("空行隔開、每點都寫 1.:同一個清單", pageMd("1. 甲\n\n1. 乙\n\n1. 丙"), "
中間一段
結論
"); check("一般段落不受影響", pageMd("第一行\n第二行\n\n第二段"), "第一行
第二行
第二段
"); if (failed) process.exitCode = 1;