(canvasLayout: CanvasLayout | null | undefined)
| 41 | } |
| 42 | |
| 43 | export function extractTextFromCanvasLayout(canvasLayout: CanvasLayout | null | undefined): string { |
| 44 | logger.info('Extracting text from canvas layout', { |
| 45 | hasCanvasLayout: !!canvasLayout, |
| 46 | hasHorizontalSections: !!canvasLayout?.horizontalSections, |
| 47 | sectionsCount: canvasLayout?.horizontalSections?.length || 0, |
| 48 | }) |
| 49 | |
| 50 | if (!canvasLayout?.horizontalSections) { |
| 51 | logger.info('No canvas layout or horizontal sections found') |
| 52 | return '' |
| 53 | } |
| 54 | |
| 55 | const textParts: string[] = [] |
| 56 | |
| 57 | for (const section of canvasLayout.horizontalSections) { |
| 58 | logger.info('Processing section', { |
| 59 | sectionId: section.id, |
| 60 | hasColumns: !!section.columns, |
| 61 | hasWebparts: !!section.webparts, |
| 62 | columnsCount: section.columns?.length || 0, |
| 63 | }) |
| 64 | |
| 65 | if (section.columns) { |
| 66 | for (const column of section.columns) { |
| 67 | if (column.webparts) { |
| 68 | for (const webpart of column.webparts) { |
| 69 | logger.info('Processing webpart', { |
| 70 | webpartId: webpart.id, |
| 71 | hasInnerHtml: !!webpart.innerHtml, |
| 72 | innerHtml: webpart.innerHtml, |
| 73 | }) |
| 74 | |
| 75 | if (webpart.innerHtml) { |
| 76 | const text = stripHtmlTags(webpart.innerHtml) |
| 77 | if (text) { |
| 78 | textParts.push(text) |
| 79 | logger.info('Extracted text', { text }) |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } else if (section.webparts) { |
| 86 | for (const webpart of section.webparts) { |
| 87 | if (webpart.innerHtml) { |
| 88 | const text = stripHtmlTags(webpart.innerHtml) |
| 89 | if (text) textParts.push(text) |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | const finalContent = textParts.join('\n\n') |
| 96 | logger.info('Final extracted content', { |
| 97 | textPartsCount: textParts.length, |
| 98 | finalContentLength: finalContent.length, |
| 99 | finalContent, |
| 100 | }) |
no test coverage detected