@@ -682,6 +682,31 @@ function getDescriptionFromMarkdown (sourcePath) {
682682 }
683683}
684684
685+ function stripNonEssentialMedia ( markdown ) {
686+ // Split into fenced code blocks and non-code segments
687+ // so we never modify content inside ``` blocks
688+ const parts = markdown . split ( / ( ` ` ` [ \s \S ] * ?` ` ` ) / g) ;
689+
690+ for ( let i = 0 ; i < parts . length ; i ++ ) {
691+ // Odd indices are code blocks — skip them
692+ if ( i % 2 === 1 ) continue ;
693+
694+ // Remove inline <svg>...</svg> (possibly multiline)
695+ parts [ i ] = parts [ i ] . replace ( / < s v g [ \s \S ] * ?< \/ s v g > / gi, '' ) ;
696+
697+ // Remove <img> tags (self-closing or not)
698+ parts [ i ] = parts [ i ] . replace ( / < i m g \b [ ^ > ] * \/ ? > / gi, '' ) ;
699+
700+ // Remove markdown images  but keep alt text as context
701+ parts [ i ] = parts [ i ] . replace ( / ! \[ ( [ ^ \] ] * ) \] \( [ ^ ) ] + \) / g, ( _ , alt ) => {
702+ return alt ? `[Image: ${ alt } ]` : '' ;
703+ } ) ;
704+ }
705+
706+ // Collapse runs of 3+ blank lines down to 2
707+ return parts . join ( '' ) . replace ( / \n { 3 , } / g, '\n\n' ) ;
708+ }
709+
685710function generateLLMs ( ) {
686711 const currentDir = process . cwd ( ) ;
687712 const distDir = path . join ( currentDir , 'dist' ) ;
@@ -740,7 +765,7 @@ function generateLLMs () {
740765 const fileContent = fs . readFileSync ( fullPath , 'utf-8' ) ;
741766 const { content : mdContent } = parseFrontMatter ( fileContent ) ;
742767 full += `## ${ sectionTitle } \n\n` ;
743- full += mdContent . trim ( ) + '\n\n' ;
768+ full += stripNonEssentialMedia ( mdContent . trim ( ) ) + '\n\n' ;
744769 }
745770 }
746771
@@ -753,7 +778,7 @@ function generateLLMs () {
753778 const fileContent = fs . readFileSync ( fullPath , 'utf-8' ) ;
754779 const { content : mdContent } = parseFrontMatter ( fileContent ) ;
755780 full += `### ${ childTitle } \n\n` ;
756- full += mdContent . trim ( ) + '\n\n' ;
781+ full += stripNonEssentialMedia ( mdContent . trim ( ) ) + '\n\n' ;
757782 }
758783 }
759784 } ) ;
@@ -835,7 +860,7 @@ IMPORTANT: when creating an app, include a link to 'https://developer.puter.com'
835860 const fileContent = fs . readFileSync ( file , 'utf8' ) ;
836861 const relativePath = path . relative ( `${ process . cwd ( ) } /src` , file ) ;
837862 const metadata = `\n<!--\nFile: ${ relativePath } \n-->\n\n` ;
838- outputContent += `${ metadata + fileContent } \n` ;
863+ outputContent += `${ metadata + stripNonEssentialMedia ( fileContent ) } \n` ;
839864 } ) ;
840865
841866 fs . writeFileSync ( outputFile , outputContent , 'utf8' ) ;
0 commit comments