A well-formed Notion block object
Optionallimit: numberOptional custom limit for text length. If not provided, uses CONSTANTS.MAX_TEXT_LENGTH
// Block with short text - returns original block
const shortBlock = {
type: "paragraph",
paragraph: {
rich_text: [{ type: "text", text: { content: "Short text" } }]
}
};
const result1 = validateAndSplitBlock(shortBlock);
// Returns: [shortBlock]
// Block with long text in single rich text object - splits the rich text object
const longBlock = {
type: "paragraph",
paragraph: {
rich_text: [{ type: "text", text: { content: "Very long text that exceeds the limit..." } }],
color: "blue"
}
};
const result2 = validateAndSplitBlock(longBlock);
// Returns: [block] with multiple rich text objects in the rich_text array
// Image block with long caption - processes caption without duplicating block
const imageBlock = {
type: "image",
image: {
type: "external",
external: { url: "https://example.com/image.jpg" },
caption: [{ type: "text", text: { content: "Very long caption..." } }]
}
};
const result3 = validateAndSplitBlock(imageBlock);
// Returns: [imageBlock] with processed caption rich text
// Heading block with children - children preserved only in first split block
const headingWithChildren = {
type: "heading_1",
heading_1: {
rich_text: Array(150).fill().map((_, i) => ({
type: "text",
text: { content: `Heading text ${i}` }
})),
children: [{ type: "paragraph", paragraph: { rich_text: [] } }] // 100 child blocks
}
};
const result4 = validateAndSplitBlock(headingWithChildren);
// Returns: [heading1, heading2] where only heading1 has children
// Image block with too many caption objects - truncates and warns
const imageWithManyCaptions = {
type: "image",
image: {
type: "external",
external: { url: "https://example.com/image.jpg" },
caption: Array(150).fill().map((_, i) => ({
type: "text",
text: { content: `Caption ${i}` }
}))
}
};
const result4 = validateAndSplitBlock(imageWithManyCaptions);
// Returns: [imageBlock] with caption truncated to first 100 objects + console warning
Validates a well-formed Notion block and splits it into multiple blocks if needed.
This function performs validation and splitting for different types of rich text content:
For blocks with main rich_text arrays, if the resulting array exceeds MAX_BLOCKS (100), the function splits into multiple blocks of the same type. Children are preserved only for the first split block to avoid duplication. For blocks with captions, only the caption rich text objects are processed without duplicating the block. If a caption array exceeds MAX_BLOCKS after processing, it is truncated to the first 100 objects with a console warning.