@@ -110,7 +110,16 @@ export function protectInlineSyntaxOutsideCode(
110110 const emptyAtxMarkers = new Map < number , string > ( ) ;
111111 const closingAtxLines = new Set < number > ( ) ;
112112 const atxHeadingLines = new Set < number > ( ) ;
113+ const blockquoteDepthByLine = new Map < number , number > ( ) ;
113114 for ( const block of ir . blocks ?? [ ] ) {
115+ if ( block . kind === "blockquote" ) {
116+ for ( let line = block . sourceStartLine ?? 0 ; line < ( block . sourceEndLine ?? 0 ) ; line += 1 ) {
117+ blockquoteDepthByLine . set (
118+ line ,
119+ Math . max ( blockquoteDepthByLine . get ( line ) ?? 0 , block . blockquoteDepth ?? 0 ) ,
120+ ) ;
121+ }
122+ }
114123 if ( block . kind === "heading" && block . headingOrigin === "atx" ) {
115124 atxHeadingLines . add ( block . sourceStartLine ?? 0 ) ;
116125 }
@@ -235,6 +244,7 @@ export function protectInlineSyntaxOutsideCode(
235244 registry ,
236245 atxHeadingLines . has ( lineIndex ) ,
237246 ! listLines . has ( lineIndex ) ,
247+ blockquoteDepthByLine . get ( lineIndex ) ?? 0 ,
238248 ) ;
239249 return thematicBreakLines . has ( lineIndex )
240250 ? line
@@ -248,9 +258,11 @@ function protectResidualBlockPadding(
248258 registry : TokenRegistry ,
249259 atxHeading : boolean ,
250260 protectQuotePadding : boolean ,
261+ blockquoteDepth : number ,
251262) : string {
252263 let protectedLine = line ;
253264 let cursor = 0 ;
265+ let consumedBlockquotes = 0 ;
254266 if ( protectQuotePadding ) {
255267 while ( cursor < protectedLine . length ) {
256268 let marker = cursor ;
@@ -264,10 +276,12 @@ function protectResidualBlockPadding(
264276 if ( protectedLine [ marker ] !== ">" ) {
265277 break ;
266278 }
279+ consumedBlockquotes += 1 ;
267280 const whitespaceStart = marker + 1 ;
268281 const whitespace = / ^ [ \t ] + / u. exec ( protectedLine . slice ( whitespaceStart ) ) ?. [ 0 ] ?? "" ;
269282 const remainingContent = protectedLine . slice ( whitespaceStart + whitespace . length ) ;
270- if ( whitespace . length > 1 && remainingContent ) {
283+ const structuralPadding = atxHeading || consumedBlockquotes < blockquoteDepth ;
284+ if ( ! structuralPadding && whitespace . length > 1 && remainingContent ) {
271285 protectedLine = `${ protectedLine . slice ( 0 , whitespaceStart + 1 ) } ${ protectLiteral (
272286 registry ,
273287 whitespace . slice ( 1 ) ,
0 commit comments