@@ -1729,9 +1729,18 @@ export const getCodeBlockContents = (content: string): object => {
17291729
17301730 let codeBlocks = [ ] ;
17311731
1732- let htmlContent = '' ;
1733- let cssContent = '' ;
1734- let jsContent = '' ;
1732+ // Groups of related HTML/CSS/JS blocks. Each HTML block starts a new group;
1733+ // CSS and JS blocks attach to the current (most recent) group.
1734+ // This preserves the existing behaviour for "dumb" models that output
1735+ // separate html/css/js blocks meant to form a single page, while also
1736+ // allowing multiple distinct HTML blocks to produce separate artifacts.
1737+ let htmlGroups : Array < { html : string ; css : string ; js : string } > = [ ] ;
1738+
1739+ const initDefaultGroup = ( ) => {
1740+ if ( htmlGroups . length === 0 ) {
1741+ htmlGroups . push ( { html : '' , css : '' , js : '' } ) ;
1742+ }
1743+ } ;
17351744
17361745 if ( codeBlockContents ) {
17371746 codeBlockContents . forEach ( ( block ) => {
@@ -1744,11 +1753,14 @@ export const getCodeBlockContents = (content: string): object => {
17441753 const { lang, code } = block ;
17451754
17461755 if ( lang === 'html' ) {
1747- htmlContent += code + '\n' ;
1756+ // Each HTML block starts a new group
1757+ htmlGroups . push ( { html : code + '\n' , css : '' , js : '' } ) ;
17481758 } else if ( lang === 'css' ) {
1749- cssContent += code + '\n' ;
1759+ initDefaultGroup ( ) ;
1760+ htmlGroups [ htmlGroups . length - 1 ] . css += code + '\n' ;
17501761 } else if ( lang === 'javascript' || lang === 'js' ) {
1751- jsContent += code + '\n' ;
1762+ initDefaultGroup ( ) ;
1763+ htmlGroups [ htmlGroups . length - 1 ] . js += code + '\n' ;
17521764 }
17531765 } ) ;
17541766 } else {
@@ -1763,28 +1775,42 @@ export const getCodeBlockContents = (content: string): object => {
17631775 if ( inlineHtml ) {
17641776 inlineHtml . forEach ( ( block ) => {
17651777 const content = block . replace ( / < \/ ? h t m l > / gi, '' ) ; // Remove <html> tags
1766- htmlContent += content + '\n' ;
1778+ htmlGroups . push ( { html : content + '\n' , css : '' , js : '' } ) ;
17671779 } ) ;
17681780 }
17691781 if ( inlineCss ) {
17701782 inlineCss . forEach ( ( block ) => {
17711783 const content = block . replace ( / < \/ ? s t y l e > / gi, '' ) ; // Remove <style> tags
1772- cssContent += content + '\n' ;
1784+ initDefaultGroup ( ) ;
1785+ htmlGroups [ htmlGroups . length - 1 ] . css += content + '\n' ;
17731786 } ) ;
17741787 }
17751788 if ( inlineJs ) {
17761789 inlineJs . forEach ( ( block ) => {
17771790 const content = block . replace ( / < \/ ? s c r i p t > / gi, '' ) ; // Remove <script> tags
1778- jsContent += content + '\n' ;
1791+ initDefaultGroup ( ) ;
1792+ htmlGroups [ htmlGroups . length - 1 ] . js += content + '\n' ;
17791793 } ) ;
17801794 }
17811795 }
17821796
1797+ // Backward-compatible flat fields (merged from all groups)
1798+ const htmlContent = htmlGroups . map ( ( g ) => g . html ) . join ( '' ) ;
1799+ const cssContent = htmlGroups . map ( ( g ) => g . css ) . join ( '' ) ;
1800+ const jsContent = htmlGroups . map ( ( g ) => g . js ) . join ( '' ) ;
1801+
17831802 return {
17841803 codeBlocks : codeBlocks ,
17851804 html : htmlContent . trim ( ) ,
17861805 css : cssContent . trim ( ) ,
1787- js : jsContent . trim ( )
1806+ js : jsContent . trim ( ) ,
1807+ htmlGroups : htmlGroups
1808+ . filter ( ( g ) => g . html . trim ( ) || g . css . trim ( ) || g . js . trim ( ) )
1809+ . map ( ( g ) => ( {
1810+ html : g . html . trim ( ) ,
1811+ css : g . css . trim ( ) ,
1812+ js : g . js . trim ( )
1813+ } ) )
17881814 } ;
17891815} ;
17901816export const parseFrontmatter = ( content ) => {
0 commit comments