File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,16 @@ const Block = ({ content }: BlockProps) => {
65
65
return < BlockComponent { ...props } /> ;
66
66
}
67
67
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
+
68
78
const augmentedProps = augmentProps ( content ) ;
69
79
70
80
return (
Original file line number Diff line number Diff line change @@ -88,6 +88,33 @@ describe('BlocksRenderer', () => {
88
88
expect ( paragraph ) . toHaveTextContent ( 'A paragraph with bold' ) ;
89
89
} ) ;
90
90
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
+
91
118
it ( 'renders quotes' , ( ) => {
92
119
render (
93
120
< BlocksRenderer
You can’t perform that action at this time.
0 commit comments