8 let heightSent = false;
9
10 function notifyParentOfHeight() {
11 // Only send height once and only if we're in an iframe
12 if (!heightSent && window.parent !== window) {
55}
56
57function escapeHtml(text: string): string {
58 return text
59 .replace(/&/g, "&")
64}
65
66function extractYouTubeId(url: string): string | null {
67 const patterns = [
68 /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([^&\n?#]+)/,
77}
78
79function extractVimeoId(url: string): string | null {
80 const match = url.match(/vimeo\.com\/(?:video\/)?(\d+)/);
81 return match ? match[1] : null;
82}
83
84function extractLoomId(url: string): string | null {
85 const match = url.match(/loom\.com\/share\/([a-zA-Z0-9]+)/);
86 return match ? match[1] : null;
87}
88
89function extractDomain(url: string): string {
90 try {
91 const urlObj = new URL(url);
96}
97
98export function GenerateHTML({ data }: any) {
99 if (!data || !data.results) {
100 return <div>No content available</div>;
156}
157
158function renderChildBlocks(children: NotionBlock[]): string {
159 if (!children || !Array.isArray(children) || children.length === 0) {
160 return "";
164}
165
166function renderBlock(block: NotionBlock): string {
167 const { type } = block;
168
217}
218
219function renderRichText(richTextArray: NotionRichText[]): string {
220 if (!richTextArray || !Array.isArray(richTextArray)) {
221 return "";
250}
251
252function renderParagraph(block: NotionBlock): string {
253 const content = renderRichText(block.paragraph?.rich_text || []);
254 return content ? `<p>${content}</p>` : "<p></p>";
255}
256
257function renderHeading(block: NotionBlock, level: number): string {
258 const headingData = block[`heading_${level}`];
259 const content = renderRichText(headingData?.rich_text || []);
261}
262
263function renderListItem(block: NotionBlock, listType: "ul" | "ol"): string {
264 const itemData =
265 block[listType === "ul" ? "bulleted_list_item" : "numbered_list_item"];
275}
276
277function renderTodo(block: NotionBlock): string {
278 const todoData = block.to_do;
279 const content = renderRichText(todoData?.rich_text || []);
289}
290
291function renderToggle(block: NotionBlock): string {
292 const toggleData = block.toggle;
293 const content = renderRichText(toggleData?.rich_text || []);
304}
305
306function renderCode(block: NotionBlock): string {
307 const codeData = block.code;
308 const content = renderRichText(codeData?.rich_text || []);
312}
313
314function renderQuote(block: NotionBlock): string {
315 const quoteData = block.quote;
316 const content = renderRichText(quoteData?.rich_text || []);
325}
326
327function renderCallout(block: NotionBlock): string {
328 const calloutData = block.callout;
329 const content = renderRichText(calloutData?.rich_text || []);
346}
347
348function renderImage(block: NotionBlock): string {
349 const imageData = block.image;
350 let imageUrl = "";
366}
367
368function renderVideo(block: NotionBlock): string {
369 const videoData = block.video;
370 let videoUrl = "";
427}
428
429function renderFile(block: NotionBlock): string {
430 const fileData = block.file;
431 let fileUrl = "";
447}
448
449function renderBookmark(block: NotionBlock): string {
450 const bookmarkData = block.bookmark;
451 const url = bookmarkData?.url || "";
474}
475
476function renderLinkPreview(block: NotionBlock): string {
477 const linkData = block.link_preview;
478 const url = linkData?.url || "";
494}
495
496function renderEmbed(block: NotionBlock): string {
497 const embedData = block.embed;
498 const url = embedData?.url || "";
588}
589
590function renderTable(block: NotionBlock): string {
591 // Tables in Notion are complex and would need child blocks to be fully rendered
592 return '<table class="notion-table"><tbody><!-- Table rows would be rendered here --></tbody></table>';
593}
594
595function renderTableRow(block: NotionBlock): string {
596 const rowData = block.table_row;
597 const cells = rowData?.cells || [];
607}
608
609function renderColumnList(block: NotionBlock): string {
610 return '<div class="column-list"><!-- Columns would be rendered here --></div>';
611}
612
613function renderColumn(block: NotionBlock): string {
614 return '<div class="column"><!-- Column content would be rendered here --></div>';
615}