File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
src/frontend/src/features/blocknote/email-exporter Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -260,6 +260,25 @@ describe('EmailExporter', () => {
260260 ] ) ;
261261 expect ( html ) . toContain ( 'background-color:#fbf3db' ) ;
262262 } ) ;
263+
264+ it ( 'renders hard breaks (Shift+Enter) as <br>' , ( ) => {
265+ const html = exportBlocks ( [
266+ paragraph ( [ styledText ( 'Line one\nLine two' ) ] ) ,
267+ ] ) ;
268+ expect ( html ) . toContain ( 'Line one' ) ;
269+ expect ( html ) . toContain ( '<br/>' ) ;
270+ expect ( html ) . toContain ( 'Line two' ) ;
271+ } ) ;
272+
273+ it ( 'renders hard breaks within styled text as <br>' , ( ) => {
274+ const html = exportBlocks ( [
275+ paragraph ( [ styledText ( 'Bold line one\nBold line two' , { bold : true } ) ] ) ,
276+ ] ) ;
277+ expect ( html ) . toContain ( 'font-weight:bold' ) ;
278+ expect ( html ) . toContain ( 'Bold line one' ) ;
279+ expect ( html ) . toContain ( '<br/>' ) ;
280+ expect ( html ) . toContain ( 'Bold line two' ) ;
281+ } ) ;
263282 } ) ;
264283
265284 // -----------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -117,12 +117,26 @@ function styleOrUndefined(style: CSSProperties): CSSProperties | undefined {
117117// Inline content rendering
118118// ---------------------------------------------------------------------------
119119
120+ function textWithBreaks ( text : string ) : React . ReactNode {
121+ if ( ! text . includes ( '\n' ) ) {
122+ return text ;
123+ }
124+ const parts = text . split ( '\n' ) ;
125+ return parts . map ( ( part , i ) => (
126+ < React . Fragment key = { i } >
127+ { part }
128+ { i < parts . length - 1 && < br /> }
129+ </ React . Fragment >
130+ ) ) ;
131+ }
132+
120133function renderStyledText ( st : AnyStyledText , key : number ) : React . ReactNode {
121134 const style = inlineStylesToCSS ( st . styles ) ;
135+ const content = textWithBreaks ( st . text ) ;
122136 if ( Object . keys ( style ) . length === 0 ) {
123- return st . text ;
137+ return < React . Fragment key = { key } > { content } </ React . Fragment > ;
124138 }
125- return < span key = { key } style = { style } > { st . text } </ span > ;
139+ return < span key = { key } style = { style } > { content } </ span > ;
126140}
127141
128142function renderInlineContent ( content : AnyInlineContent [ ] ) : React . ReactNode [ ] {
You can’t perform that action at this time.
0 commit comments