Skip to content

Commit c0c971c

Browse files
wesbillmanCarl
andauthored
fix(desktop): keep collapsed table separators out of spoilers (#3169)
## Summary - preserve collapsed GFM table separator rows as literal text - prevent `||---:|---|---||` from becoming an animated spoiler canvas - leave normal spoilers and valid multiline tables unchanged ## Root cause When table newlines are lost, adjacent row pipes become `||`. The spoiler remark plugin interpreted the delimiter row between those pairs as a hidden spoiler, so the reported "static" was the spoiler particle animation rather than table layout churn. ## Safety The guard only applies to a paragraph span made entirely of text that exactly matches a multi-column GFM delimiter row. The narrow syntax collision is that an intentional spoiler containing only a delimiter row such as `||---|---||` now renders literally. ## Verification - desktop pre-push checks passed (3,662 tests) - desktop TypeScript typecheck passed - independent review found no blocking issues Signed-off-by: Wes <[email protected]> Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
1 parent c116c9a commit c0c971c

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎desktop/src/shared/lib/remarkSpoilers.test.mjs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ test("remarkSpoilers: groups block nodes between delimiter paragraphs", () => {
137137
assert.equal(tree.children[1].children[0].children[0].type, "image");
138138
});
139139

140+
test("remarkSpoilers: leaves collapsed GFM table separators as text", () => {
141+
const value =
142+
"| Time | Purpose ||---:|---|| 0:00 | Frame strategy || 3:30 | Orient the board |";
143+
const tree = runPlugin({
144+
type: "root",
145+
children: [{ type: "paragraph", children: [{ type: "text", value }] }],
146+
});
147+
148+
assert.equal(
149+
tree.children[0].children.some((child) => child.type === "spoiler"),
150+
false,
151+
);
152+
assert.equal(
153+
tree.children[0].children.map((child) => child.value ?? "").join(""),
154+
value,
155+
);
156+
});
157+
140158
test("remarkSpoilers: leaves unmatched delimiters as text", () => {
141159
const tree = runPlugin({
142160
type: "root",

‎desktop/src/shared/lib/remarkSpoilers.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,29 @@ function transformNode(node: Node) {
3737
transformNode(child);
3838
}
3939

40-
node.children = groupBlockSpoilers(groupSpoilers(node.children));
40+
node.children = groupBlockSpoilers(
41+
groupSpoilers(node.children, node.type === "paragraph"),
42+
);
4143
}
4244

43-
function groupSpoilers(children: Node[]): Node[] {
45+
function groupSpoilers(
46+
children: Node[],
47+
rejectTableDelimiterRow: boolean,
48+
): Node[] {
4449
const output: Node[] = [];
4550
let spoilerBuffer: Node[] | null = null;
4651

4752
for (const part of splitDelimiterParts(children)) {
4853
if (part.type === "delimiter") {
4954
if (spoilerBuffer) {
50-
output.push(buildSpoilerNode(spoilerBuffer));
55+
if (rejectTableDelimiterRow && isTableDelimiterRow(spoilerBuffer)) {
56+
output.push({ type: "text", value: "||" }, ...spoilerBuffer, {
57+
type: "text",
58+
value: "||",
59+
});
60+
} else {
61+
output.push(buildSpoilerNode(spoilerBuffer));
62+
}
5163
spoilerBuffer = null;
5264
} else {
5365
spoilerBuffer = [];
@@ -100,6 +112,13 @@ function splitDelimiterParts(children: Node[]): Part[] {
100112
return parts;
101113
}
102114

115+
function isTableDelimiterRow(children: Node[]): boolean {
116+
if (children.some((child) => child.type !== "text")) return false;
117+
118+
const value = children.map((child) => String(child.value ?? "")).join("");
119+
return /^\s*:?-{3,}:?(?:\s*\|\s*:?-{3,}:?)+\s*$/.test(value);
120+
}
121+
103122
function buildSpoilerNode(
104123
children: Node[],
105124
options: { block?: boolean } = {},

0 commit comments

Comments
 (0)