@@ -1097,8 +1097,9 @@ export default class ExpensiMark {
10971097 return ;
10981098 }
10991099
1100+ const nextItem = splitText ?. [ index + 1 ] ;
11001101 // Insert '\n' unless it ends with '\n' or '>' or it's the last element, or if it's a header ('# ') with a space.
1101- if ( text . match ( / [ \n | > ] [ > ] ? [ \s ] ? $ / ) || index === splitText . length - 1 || text === '# ' ) {
1102+ if ( ( nextItem && text . match ( / > [ \s ] ? $ / ) && ! nextItem . startsWith ( '> ' ) ) || text . match ( / \n [ \s ] ? $ / ) || index === splitText . length - 1 || text === '# ' ) {
11021103 joinedText += text ;
11031104 } else {
11041105 joinedText += `${ text } \n` ;
@@ -1111,20 +1112,22 @@ export default class ExpensiMark {
11111112 }
11121113
11131114 unpackNestedQuotes ( text : string ) : string {
1114- let parsedText = text . replace ( / ( < \/ b l o c k q u o t e > ) + / g, ( match ) => {
1115- return `${ match . slice ( 0 , match . lastIndexOf ( '</blockquote>' ) ) } </blockquote><br / >` ;
1115+ let parsedText = text . replace ( / ( ( < \/ b l o c k q u o t e > ) + ( < b r \/ > ) ? ) | ( < b r \/ > ) / g, ( match ) => {
1116+ return `${ match } </split >` ;
11161117 } ) ;
1117- const splittedText = parsedText . split ( '<br / >' ) ;
1118+ const splittedText = parsedText . split ( '</split >' ) ;
11181119 if ( splittedText . length > 0 && splittedText [ splittedText . length - 1 ] === '' ) {
11191120 splittedText . pop ( ) ;
11201121 }
11211122
11221123 let count = 0 ;
11231124 parsedText = splittedText
1124- . map ( ( line , index , arr ) => {
1125- if ( line === '' ) {
1125+ . map ( ( l ) => {
1126+ const hasBR = l . endsWith ( '<br />' ) ;
1127+ if ( l === '' && count === 0 ) {
11261128 return '' ;
11271129 }
1130+ const line = l . replace ( / ( < b r \/ > ) $ / g, '' ) ;
11281131
11291132 if ( line . startsWith ( '<blockquote>' ) ) {
11301133 count += ( line . match ( / < b l o c k q u o t e > / g) || [ ] ) . length ;
@@ -1140,7 +1143,7 @@ export default class ExpensiMark {
11401143 return `${ line } ${ '</blockquote>' } ${ '<blockquote>' . repeat ( count ) } ` ;
11411144 }
11421145
1143- return line + ( index < arr . length - 1 ? '<br />' : '' ) ;
1146+ return line + ( hasBR ? '<br />' : '' ) ;
11441147 } )
11451148 . join ( '' ) ;
11461149
0 commit comments