{codeMatch[1]}
);
}
return part;
});
}
function formatChildren(children: React.ReactNode): React.ReactNode {
if (typeof children === "string") {
return formatInlineText(children);
}
if (Array.isArray(children)) {
return React.Children.map(children, (child) => {
if (typeof child === "string") {
return formatInlineText(child);
}
return child;
});
}
return children;
}
// Preprocess Portable Text blocks to handle Notion callouts, Scenarios, frontmatter cleanup, and clean structure
function preprocessPortableText(blocks: any[]): any[] {
if (!Array.isArray(blocks)) return blocks;
const result: any[] = [];
let i = 0;
while (i < blocks.length) {
const block = blocks[i];
const text = block.children?.map((c: any) => c.text).join("") || "";
const trimmed = text.trim();
// 0. Skip frontmatter metadata blocks leftover from markdown import
if (
i < 12 &&
/^(title|slug|customPath|pageId|createdTime|lastEditedTime|cover):/i.test(
trimmed
)
) {
i++;
continue;
}
// 0b. Skip redundant duplicate title H1/H2 at the very beginning of the article
if (
i < 5 &&
(block.style === "h1" || block.style === "h2") &&
(/vietnam luxury wedding cost/i.test(trimmed) ||
/ngân sách tiệc cưới cao cấp/i.test(trimmed))
) {
i++;
continue;
}
// 1. Detect Notion Callout pattern (| {formatInlineText(cell)} | ))}
|---|
| {formatInlineText(cell)} | ))}
{formatInlineText(p)}
)) : value.content}); }, scenariosGrid: ({ value }) => { return ({formatInlineText(value.content)}
{upsideLabel} {" "} {formatInlineText(scen.upside)}
)} {scen.downside && ({downsideLabel} {" "} {formatInlineText(scen.downside)}
)}
{tokens.map((line, i) => (
{line.map((token, key) => (
))}
))}
)}
{formatChildren(children)}
); }, h1: ({ children }) => ({formatChildren(children)}), }, marks: { link: ({ value, children }) => { const isExternal = (value?.href || "").startsWith("http") || (value?.href || "").startsWith("https") || (value?.href || "").startsWith("mailto"); const target = isExternal ? "_blank" : undefined; return ( {children} ); }, strong: ({ children }) => ( {children} ), em: ({ children }) => ( {children} ), }, list: { bullet: ({ children }) => (