mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +03:00
An empty Notion table was converted to a schema-invalid table node with no rows. Node.fromJSON accepts it, but Markdown serialization then crashed in renderTable's node.child(0), surfacing only "Index 0 out of range for <>". Drop empty tables in the Notion converter, and guard renderTable against tables with no rows so any source is handled safely. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { Node } from "prosemirror-model";
|
|
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
|
|
import nodesWithEmptyTextNode from "@server/test/fixtures/notion-page-with-empty-text-nodes.json";
|
|
import allNodes from "@server/test/fixtures/notion-page.json";
|
|
import type { ProsemirrorData, ProsemirrorDoc } from "@shared/types";
|
|
import type { NotionPage } from "./NotionConverter";
|
|
import { NotionConverter } from "./NotionConverter";
|
|
|
|
const generatedId = "550e8400-e29b-41d4-a716-446655440000";
|
|
|
|
function normalizeGeneratedIds(node: ProsemirrorDoc | ProsemirrorData) {
|
|
if (node.type === "container_toggle" && node.attrs) {
|
|
node.attrs.id = generatedId;
|
|
}
|
|
|
|
node.content?.forEach(normalizeGeneratedIds);
|
|
}
|
|
|
|
describe("NotionConverter", () => {
|
|
it("converts a page", () => {
|
|
const response = NotionConverter.page({
|
|
children: allNodes,
|
|
} as NotionPage);
|
|
|
|
normalizeGeneratedIds(response);
|
|
expect(response).toMatchSnapshot();
|
|
expect(ProsemirrorHelper.toProsemirror(response)).toBeInstanceOf(Node);
|
|
});
|
|
|
|
it("converts a page with empty text nodes", () => {
|
|
const response = NotionConverter.page({
|
|
children: nodesWithEmptyTextNode,
|
|
} as NotionPage);
|
|
|
|
normalizeGeneratedIds(response);
|
|
expect(response).toMatchSnapshot();
|
|
expect(ProsemirrorHelper.toProsemirror(response)).toBeInstanceOf(Node);
|
|
});
|
|
|
|
it("drops an empty table", () => {
|
|
const response = NotionConverter.page({
|
|
children: [
|
|
{
|
|
object: "block",
|
|
id: "1b32c2bb-bca8-8022-b490-e42a8f6b00f5",
|
|
type: "table",
|
|
has_children: false,
|
|
table: {
|
|
table_width: 0,
|
|
has_column_header: false,
|
|
has_row_header: false,
|
|
},
|
|
},
|
|
],
|
|
} as unknown as NotionPage);
|
|
|
|
expect(response.content).toEqual([]);
|
|
expect(ProsemirrorHelper.toProsemirror(response)).toBeInstanceOf(Node);
|
|
});
|
|
});
|