Files
outline/shared/editor/rules/checkboxes.test.ts
T
Tom Moor 5ea63aa1a2 fix: Editor math block parsing and NaN media dimensions (#12668)
* fix: Block math not closed by trailing $$ on a content line

The closing delimiter check compared a 3-character slice against the
2-character "$$" delimiter, so block math closed on the same line as
content (e.g. "c = d$$") was never detected and the block swallowed the
rest of the document. Use the delimiter length rather than a hardcoded
slice. Also fix the indexOf sentinel comparison (!== 1 instead of
!== -1) in inline math parsing, which terminated correctly only by
coincidence.

Adds tests for the math markdown rules and moves the findNodes test
helper into shared/test/editor for reuse.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: NaN width and height parsed for video and image nodes

Video parseDOM and parseMarkdown used parseInt on a missing attribute,
storing NaN instead of null and persisting it to markdown as NaNxNaN.
Image size syntax with a missing dimension (e.g. "=x100") hit the same
issue through optional regex groups. Parse dimensions only when
present, matching the existing guard in Image parseDOM, and correct the
video getAttrs element type.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: Normalize non-numeric video dimensions, avoid serializing nullxnull

Review feedback: parseInt could still produce NaN when the attribute
exists but is not numeric (e.g. width="auto"), and toMarkdown wrote
null dimensions as "nullxnull". Parse dimensions through a helper that
normalizes non-finite values to null, and serialize nullish dimensions
as empty strings, which still round-trips as a video node.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 22:29:29 -04:00

57 lines
1.9 KiB
TypeScript

import { extensionManager, findNodes, schema } from "../../test/editor";
const serializer = extensionManager.serializer();
const parser = extensionManager.parser({
schema,
plugins: extensionManager.rulePlugins,
});
it("preserves mixed checkbox and regular items in a list", () => {
const markdown = `- [x] Checked item
- Regular item
- [ ] Unchecked item`;
const ast = parser.parse(markdown);
const [checkboxList] = findNodes(ast?.toJSON(), "checkbox_list");
expect(checkboxList).toBeDefined();
expect(checkboxList?.content).toHaveLength(3);
expect(checkboxList?.content?.[0].type).toBe("checkbox_item");
expect(checkboxList?.content?.[1].type).toBe("checkbox_item");
expect(checkboxList?.content?.[2].type).toBe("checkbox_item");
});
it("round-trips mixed checkbox lists through serializer", () => {
const markdown = `- [x] Checked
- Plain text
- [ ] Unchecked`;
const ast = parser.parse(markdown);
const output = serializer.serialize(ast);
// All items should survive the round-trip
expect(output).toContain("Checked");
expect(output).toContain("Plain text");
expect(output).toContain("Unchecked");
});
it("does not convert nested bullet list items inside checkbox lists", () => {
const markdown = `- [x] Parent checkbox
- Nested bullet item
- Another nested item
- [ ] Second checkbox`;
const ast = parser.parse(markdown);
const [checkboxList] = findNodes(ast?.toJSON(), "checkbox_list");
expect(checkboxList).toBeDefined();
expect(checkboxList?.content).toHaveLength(2);
expect(checkboxList?.content?.[0].type).toBe("checkbox_item");
expect(checkboxList?.content?.[1].type).toBe("checkbox_item");
// Nested list should remain a bullet_list, not a checkbox_list
const [nestedList] = findNodes(checkboxList?.content?.[0], "bullet_list");
expect(nestedList).toBeDefined();
expect(nestedList?.content?.[0].type).toBe("list_item");
});