File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,6 +65,16 @@ const Block = ({ content }: BlockProps) => {
6565 return < BlockComponent { ...props } /> ;
6666 }
6767
68+ // Handle empty paragraphs separately as they should render a <br> tag
69+ if (
70+ type === 'paragraph' &&
71+ childrenNodes . length === 1 &&
72+ childrenNodes [ 0 ] . type === 'text' &&
73+ childrenNodes [ 0 ] . text === ''
74+ ) {
75+ return < br /> ;
76+ }
77+
6878 const augmentedProps = augmentProps ( content ) ;
6979
7080 return (
Original file line number Diff line number Diff line change @@ -88,6 +88,33 @@ describe('BlocksRenderer', () => {
8888 expect ( paragraph ) . toHaveTextContent ( 'A paragraph with bold' ) ;
8989 } ) ;
9090
91+ it ( 'renders a br when there is an empty paragraph' , ( ) => {
92+ render (
93+ < BlocksRenderer
94+ content = { [
95+ {
96+ type : 'paragraph' ,
97+ children : [ { type : 'text' , text : 'First paragraph' } ] ,
98+ } ,
99+ // empty paragraph
100+ {
101+ type : 'paragraph' ,
102+ children : [ { type : 'text' , text : '' } ] ,
103+ } ,
104+ {
105+ type : 'paragraph' ,
106+ children : [ { type : 'text' , text : 'Second paragraph' } ] ,
107+ } ,
108+ ] }
109+ />
110+ ) ;
111+
112+ // eslint-disable-next-line testing-library/no-node-access
113+ const brElement = screen . getByText ( 'First paragraph' ) . nextElementSibling ;
114+ expect ( brElement ) . toBeInTheDocument ( ) ;
115+ expect ( brElement ?. tagName ) . toBe ( 'BR' ) ;
116+ } ) ;
117+
91118 it ( 'renders quotes' , ( ) => {
92119 render (
93120 < BlocksRenderer
You can’t perform that action at this time.
0 commit comments