Skip to content

Commit 3744000

Browse files
committed
feat(choro): 文件清单渲染美化——竖线等宽行换真 table(桌面实测反馈)
- renderWikiMarkdown:连续 | 行解析成真表格(表头/分隔行对齐元数据/路径 单元格等宽底色/行数右对齐 tabular-nums/斑马纹+hover);\| 转义还原; 路径形单元格启发式(含 / 且以扩展名结尾)→ code 底色。 - 引导引言(blockquote)缩小一档;表格 CSS 全走语义色层(3% 前景混色 斑马纹,无新字面量色,contrast 审计过)。 - 回归锁三件:真 table / 分隔行被消费 / 数字列对齐。全量 106/106(client +contrast);check-sync 94 一致。
1 parent 56ffe33 commit 3744000

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

‎dsh-mneme/lib/client.js‎

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,8 +2339,16 @@ window.__ModuleLoader__.load({
23392339
".mneme-wikipage li{font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary);margin:3px 0}",
23402340
".mneme-wikipre{margin:10px 0;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-layer-1));overflow-x:auto;font-size:12px;line-height:18px;color:var(--dsw-alias-label-primary);white-space:pre}",
23412341
".mneme-wikicode{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-active);border-radius:4px;padding:1px 5px}",
2342-
".mneme-wikitablerow{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:11.5px;line-height:19px;color:var(--dsw-alias-label-secondary);white-space:pre;overflow-x:auto}",
2343-
".mneme-wikiquote{margin:8px 0;padding:6px 12px;border-left:3px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);font-size:12.5px;line-height:19px}",
2342+
// 表格(v0.11.1 美化):真 table 替代竖线等宽行;文件清单第一列路径走
2343+
// code 底色,行数列右对齐等宽数字;斑马纹用 3% 前景混色,不引新字面量色。
2344+
".mneme-wikitable{width:100%;border-collapse:collapse;margin:10px 0 14px;font-size:12.5px}",
2345+
".mneme-wikitable th{padding:6px 10px;border-bottom:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);font-weight:500;text-align:left;white-space:nowrap}",
2346+
".mneme-wikitable td{padding:5px 10px;border-top:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);vertical-align:top}",
2347+
".mneme-wikitable tbody tr:nth-child(even){background:color-mix(in srgb,var(--dsw-alias-label-primary) 3%,transparent)}",
2348+
".mneme-wikitable tbody tr:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 7%,transparent)}",
2349+
".mneme-wikitable td .mneme-wikicode{background:none;padding:0}",
2350+
".mneme-wikinum{text-align:right;font-variant-numeric:tabular-nums}",
2351+
".mneme-wikiquote{margin:8px 0 14px;padding:8px 12px;border-left:3px solid var(--dsw-alias-border-l2);color:var(--mneme-fg-dim);font-size:12px;line-height:18px}",
23442352
".mneme-wikiempty{padding:26px 22px;font-size:13px;line-height:21px;color:var(--dsw-alias-label-secondary);display:flex;flex-direction:column;gap:8px;overflow-y:auto}",
23452353
".mneme-wikiemptytitle{font-size:15px;font-weight:600;color:var(--dsw-alias-label-primary)}",
23462354
".mneme-wikihits{position:absolute;inset-inline:22px;top:8px;z-index:3;display:flex;flex-direction:column;gap:4px;max-height:46%;overflow-y:auto;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:8px;box-shadow:0 10px 28px color-mix(in srgb,var(--dsw-alias-label-primary) 14%,transparent)}",
@@ -10296,39 +10304,78 @@ window.__ModuleLoader__.load({
1029610304
let listItems = [];
1029710305
let inCode = false;
1029810306
let codeLines = [];
10307+
// --- 表格(v0.11.1 美化):连续 `|` 行解析成真 table,不再按等宽行画竖线 ---
10308+
const splitRow = (line) => String(line).trim().replace(/^\|/, "").replace(/\|$/, "")
10309+
.split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, "|"));
10310+
const isSepRow = (cells) => cells.length > 0 && cells.every((c) => /^:?-{3,}:?$/.test(c));
10311+
// 路径形单元格(含 / 且以扩展名结尾)渲染成等宽 code——文件清单的第一列
10312+
// 是相对路径,等宽 + 深一点的底色让路径在表里一眼可辨。
10313+
const pathLike = (text) => /^(?!https?:)(?:[\w.-]+\/)*[\w.-]+\.[A-Za-z]{1,5}$/.test(String(text).trim());
10314+
const cellNodes = (text, key) => {
10315+
const trimmed = String(text).trim();
10316+
if (pathLike(trimmed)) return h("code", { key, className: "mneme-wikicode" }, trimmed);
10317+
return inline(trimmed);
10318+
};
10319+
let tableRows = null;
10320+
const flushTable = () => {
10321+
if (!tableRows) return;
10322+
const rows = tableRows;
10323+
tableRows = null;
10324+
if (rows.length === 0) return;
10325+
const headerCells = splitRow(rows[0]);
10326+
const sepIndex = rows.length > 1 && isSepRow(splitRow(rows[1])) ? 1 : -1;
10327+
const aligns = sepIndex >= 0
10328+
? splitRow(rows[sepIndex]).map((c) => (c.endsWith(":") ? "right" : c.startsWith(":") ? "center" : null))
10329+
: headerCells.map(() => null);
10330+
const bodyStart = sepIndex >= 0 ? sepIndex + 1 : 0;
10331+
const head = h("thead", { key: "h" }, h("tr", null,
10332+
headerCells.map((c, idx) => h("th", {
10333+
key: idx, style: aligns[idx] ? { textAlign: aligns[idx] } : undefined,
10334+
}, cellNodes(c, idx)))));
10335+
const body = h("tbody", { key: "b" }, rows.slice(bodyStart).map((row, rIdx) => {
10336+
const cells = splitRow(row);
10337+
return h("tr", { key: rIdx }, headerCells.map((_, idx) => h("td", {
10338+
key: idx,
10339+
className: aligns[idx] === "right" ? "mneme-wikinum" : undefined,
10340+
style: aligns[idx] && aligns[idx] !== "right" ? { textAlign: aligns[idx] } : undefined,
10341+
}, cellNodes(cells[idx] ?? "", idx))));
10342+
}));
10343+
out.push(h("table", { key: out.length, className: "mneme-wikitable" }, head, body));
10344+
};
1029910345
for (; i < lines.length; i++) {
1030010346
const line = lines[i];
1030110347
if (line.trim().startsWith("```")) {
1030210348
if (inCode) {
1030310349
out.push(h("pre", { key: out.length, className: "mneme-wikipre" }, codeLines.join("\n")));
1030410350
codeLines = []; inCode = false;
10305-
} else { flushList(); inCode = true; }
10351+
} else { flushList(); flushTable(); inCode = true; }
1030610352
continue;
1030710353
}
1030810354
if (inCode) { codeLines.push(line); continue; }
1030910355
const heading = line.match(/^(#{1,6})\s+(.*)$/);
1031010356
if (heading) {
10311-
flushList();
10357+
flushList(); flushTable();
1031210358
const level = Math.min(heading[1].length + 1, 5);
1031310359
out.push(h(`h${level}`, { key: out.length }, inline(heading[2])));
1031410360
continue;
1031510361
}
1031610362
const ul = line.match(/^\s*[-*]\s+(.*)$/);
1031710363
const ol = line.match(/^\s*\d+[.)]\s+(.*)$/);
1031810364
if (ul || ol) {
10365+
flushTable();
1031910366
const want = ul ? "ul" : "ol";
1032010367
if (list !== want) flushList();
1032110368
list = want;
1032210369
listItems.push(h("li", { key: listItems.length }, inline(ul ? ul[1] : ol[1])));
1032310370
continue;
1032410371
}
10325-
flushList();
10326-
if (/^\s*\|/.test(line)) { out.push(h("div", { key: out.length, className: "mneme-wikitablerow" }, inline(line.trim()))); continue; }
10372+
if (/^\s*\|/.test(line)) { flushList(); tableRows = tableRows ?? []; tableRows.push(line); continue; }
10373+
flushList(); flushTable();
1032710374
if (/^>\s?/.test(line)) { out.push(h("blockquote", { key: out.length, className: "mneme-wikiquote" }, inline(line.replace(/^>\s?/, "")))); continue; }
1032810375
if (line.trim() === "") continue;
1032910376
out.push(h("p", { key: out.length }, inline(line)));
1033010377
}
10331-
flushList();
10378+
flushList(); flushTable();
1033210379
if (inCode && codeLines.length > 0) out.push(h("pre", { key: out.length, className: "mneme-wikipre" }, codeLines.join("\n")));
1033310380
return out;
1033410381
}

‎dsh-mneme/test/client.test.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ test("chorography wiki page exposes the rebuild action against /choro/run", () =
135135
);
136136
});
137137

138+
// v0.11.1 美化:文件清单的竖线等宽行换成真 table(用户实测反馈「文件名排列
139+
// 太难看」)。锁渲染器三件事:真 <table>、分隔行(--- | ---:)按对齐元数据消费
140+
// 而不是画成可见行、数字列右对齐。回归表现:改回竖线等宽行画法 → 红在缺 table。
141+
test("chorography wiki page renders markdown tables as real aligned tables", () => {
142+
assert.ok(
143+
clientSource.includes("mneme-wikitable"),
144+
"the markdown renderer must emit real table elements"
145+
);
146+
assert.ok(
147+
clientSource.includes("isSepRow"),
148+
"the separator row (--- | ---:) must be consumed as alignment metadata, not rendered"
149+
);
150+
assert.ok(
151+
clientSource.includes("mneme-wikinum"),
152+
"numeric columns (行数) must be right-aligned via the alignment marker"
153+
);
154+
});
155+
138156
// 上一条锁的是「代码里有没有这两套座位」,这条锁「装/卸真的按条件跑」。
139157
// 回归表现(都靠字符串锁抓不到):
140158
// · 新宿主上两套都装 → 侧栏两颗记忆入口;

0 commit comments

Comments
 (0)