@@ -347,13 +347,12 @@ export const parse_multiple_files = (params: {
347347 ( ( current_language == 'markdown' || current_language == 'md' ) &&
348348 i > 0 &&
349349 ( lines [ i - 1 ] . trim ( ) == '' ||
350- lines [ i - 1 ] . trim ( ) . endsWith ( '```' ) ) ) ) &&
350+ ( current_file_name . endsWith ( '.md' ) &&
351+ lines [ i - 1 ] . trim ( ) . endsWith ( '```' ) ) ) ) ) &&
351352 ( ( ) => {
352353 for ( let j = i + 1 ; j < lines . length ; j ++ ) {
353354 const next_line = lines [ j ] . trim ( )
354- if ( next_line !== '' ) {
355- return ! next_line . startsWith ( '```' )
356- }
355+ if ( next_line ) return true
357356 }
358357 return false
359358 } ) ( )
@@ -363,6 +362,12 @@ export const parse_multiple_files = (params: {
363362 backtick_nesting_level ++
364363 } else if ( trimmed_line . endsWith ( '```' ) ) {
365364 backtick_nesting_level --
365+ if (
366+ backtick_nesting_level === 1 &&
367+ ( current_language === 'markdown' || current_language === 'md' )
368+ ) {
369+ is_first_content_line = true
370+ }
366371 }
367372
368373 if ( backtick_nesting_level <= 0 ) {
@@ -500,6 +505,30 @@ export const parse_multiple_files = (params: {
500505 }
501506
502507 if ( extracted_filename ) {
508+ if (
509+ ( current_language === 'markdown' || current_language === 'md' ) &&
510+ current_file_name
511+ ) {
512+ // This is a new file inside a markdown block. Save the previous one.
513+ const cleaned_content = current_content . trim ( )
514+ if ( has_real_code ( cleaned_content ) ) {
515+ const file_key = `${
516+ current_workspace_name || ''
517+ } :${ current_file_name } `
518+ if ( files_map . has ( file_key ) ) {
519+ const existing_file = files_map . get ( file_key ) !
520+ existing_file . content += '\n\n' + cleaned_content
521+ } else {
522+ files_map . set ( file_key , {
523+ file_path : current_file_name ,
524+ content : cleaned_content ,
525+ workspace_name : current_workspace_name
526+ } )
527+ }
528+ }
529+ current_content = ''
530+ }
531+
503532 const { workspace_name, relative_path } =
504533 extract_workspace_and_path (
505534 extracted_filename ,
0 commit comments