@@ -102,6 +102,17 @@ function sanitizeUrl(url: string, cfg: ResolvedReactConfig): string | undefined
102102 return url ;
103103}
104104
105+ /**
106+ * React equivalent of HTML renderers' `children || '<br/>'` behavior.
107+ * Keeps empty block lines visible and structurally consistent.
108+ */
109+ function withEmptyBlockPlaceholder ( children : ReactNode ) : ReactNode {
110+ if ( children === null || children === undefined || children === false || children === '' ) {
111+ return createElement ( 'br' ) ;
112+ }
113+ return children ;
114+ }
115+
105116// ─── Node Override Helpers ─────────────────────────────────────────────────
106117
107118function renderCodeBlockContainer ( node : TNode , cfg : ResolvedReactConfig ) : ReactNode {
@@ -148,18 +159,18 @@ export function buildRendererConfig(
148159 blocks : {
149160 paragraph : withCustomComponent ( cfg , 'paragraph' , ( node , children ) => {
150161 const tag = resolveTag ( cfg , 'paragraph' , node , 'p' ) ;
151- return createElement ( tag , null , children || null ) ;
162+ return createElement ( tag , null , withEmptyBlockPlaceholder ( children ) ) ;
152163 } ) ,
153164
154165 header : withCustomComponent ( cfg , 'header' , ( node , children ) => {
155166 const level = getHeaderLevel ( node ) ;
156167 const tag = resolveTag ( cfg , 'header' , node , `h${ level } ` ) ;
157- return createElement ( tag , null , children || null ) ;
168+ return createElement ( tag , null , withEmptyBlockPlaceholder ( children ) ) ;
158169 } ) ,
159170
160171 blockquote : withCustomComponent ( cfg , 'blockquote' , ( node , children ) => {
161172 const tag = resolveTag ( cfg , 'blockquote' , node , 'blockquote' ) ;
162- return createElement ( tag , null , children || null ) ;
173+ return createElement ( tag , null , withEmptyBlockPlaceholder ( children ) ) ;
163174 } ) ,
164175
165176 'code-block' : withCustomComponent ( cfg , 'code-block' , {
@@ -168,7 +179,7 @@ export function buildRendererConfig(
168179 const props : Record < string , unknown > = { className : meta . className } ;
169180 if ( meta . language ) props [ 'data-language' ] = meta . language ;
170181 const tag = resolveTag ( cfg , 'code-block' , node , 'pre' ) ;
171- return createElement ( tag , props , children || null ) ;
182+ return createElement ( tag , props , withEmptyBlockPlaceholder ( children ) ) ;
172183 } ,
173184 toProps : ( meta ) => {
174185 const props : Record < string , unknown > = { className : meta . className } ;
@@ -183,7 +194,11 @@ export function buildRendererConfig(
183194 const props : Record < string , unknown > = { } ;
184195 if ( checked !== undefined ) props [ 'data-checked' ] = checked ;
185196 const tag = resolveTag ( cfg , 'list-item' , node , 'li' ) ;
186- return createElement ( tag , Object . keys ( props ) . length > 0 ? props : null , children || null ) ;
197+ return createElement (
198+ tag ,
199+ Object . keys ( props ) . length > 0 ? props : null ,
200+ withEmptyBlockPlaceholder ( children ) ,
201+ ) ;
187202 } ,
188203 toProps : ( checked ) => {
189204 if ( checked !== undefined ) return { 'data-checked' : checked } ;
0 commit comments