@@ -782,6 +782,20 @@ export interface MarkdownSplit {
782782 readonly gapRows : number ;
783783}
784784
785+ /** Build a split whose live tail starts at `firstContent`; one blank line
786+ * between the frozen boundary and the live tail collapses to a single gap row. */
787+ function settledSplit (
788+ frozen : string ,
789+ rest : string [ ] ,
790+ firstContent : number ,
791+ ) : MarkdownSplit {
792+ return {
793+ frozen,
794+ live : rest . slice ( firstContent ) . join ( "\n" ) ,
795+ gapRows : firstContent > 0 ? 1 : 0 ,
796+ } ;
797+ }
798+
785799export function splitAtSettledHeading ( text : string ) : MarkdownSplit | null {
786800 const lines = text . split ( "\n" ) ;
787801 const insideFence = fencedLineMask ( lines ) ;
@@ -797,11 +811,11 @@ export function splitAtSettledHeading(text: string): MarkdownSplit | null {
797811 const firstContent = rest . findIndex ( ( line ) => line . trim ( ) . length > 0 ) ;
798812 // Heading closed but nothing has started under it yet.
799813 if ( firstContent === - 1 ) return null ;
800- return {
801- frozen : lines . slice ( 0 , boundary + 1 ) . join ( "\n" ) ,
802- live : rest . slice ( firstContent ) . join ( "\n" ) ,
803- gapRows : firstContent > 0 ? 1 : 0 ,
804- } ;
814+ return settledSplit (
815+ lines . slice ( 0 , boundary + 1 ) . join ( "\n" ) ,
816+ rest ,
817+ firstContent ,
818+ ) ;
805819}
806820
807821/**
@@ -870,11 +884,11 @@ export function splitAtSettledBlock(withheld: string): MarkdownSplit | null {
870884 const rest = lines . slice ( boundary + 1 ) ;
871885 const firstContent = rest . findIndex ( ( entry ) => entry . trim ( ) . length > 0 ) ;
872886 if ( firstContent === - 1 ) continue ;
873- return {
874- frozen : lines . slice ( 0 , boundary + 1 ) . join ( "\n" ) ,
875- live : rest . slice ( firstContent ) . join ( "\n" ) ,
876- gapRows : firstContent > 0 ? 1 : 0 ,
877- } ;
887+ return settledSplit (
888+ lines . slice ( 0 , boundary + 1 ) . join ( "\n" ) ,
889+ rest ,
890+ firstContent ,
891+ ) ;
878892 }
879893 return null ;
880894}
0 commit comments