File tree 4 files changed +21
-15
lines changed
4 files changed +21
-15
lines changed Original file line number Diff line number Diff line change 46
46
"react-dom" : " ^18.3.1" ,
47
47
"react-error-boundary" : " ^4.0.13" ,
48
48
"react-i18next" : " ^15.0.1" ,
49
- "react-nl2br" : " ^1.0.4" ,
50
49
"react-router-dom" : " ^6.26.0" ,
51
50
"sharp" : " ^0.33.4" ,
52
51
"siwe" : " ^2.3.2" ,
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import type { MediaAttributes } from '@/types/strapi';
10
10
import { BlocksRenderer } from '@strapi/blocks-react-renderer' ;
11
11
import type { RootNode } from 'node_modules/@strapi/blocks-react-renderer/dist/BlocksRenderer' ;
12
12
import { isValidElement , type JSX , type ReactElement } from 'react' ;
13
- import nl2br from 'react-nl2br ' ;
13
+ import newlineToBr from 'src/utils/newlineToBr ' ;
14
14
import { BlogParagraphContainer } from './BlogArticle/BlogArticle.style' ;
15
15
import type { BlogWidgetProps } from './BlogWidget' ;
16
16
import { BlogWidget } from './BlogWidget' ;
@@ -238,12 +238,12 @@ export const CustomRichBlocks = ({
238
238
</ BlogLink >
239
239
) ;
240
240
} else {
241
- const nl2brText : Array < ReactElement | string > = nl2br (
241
+ const nl2brText : Array < ReactElement | string > = newlineToBr (
242
242
el . props . text ,
243
243
) ;
244
244
return nl2brText . map ( ( line , lineIndex : number ) => {
245
245
if ( isValidElement ( line ) && line . type === 'br' ) {
246
- // adds <br> from nl2br
246
+ // adds <br>
247
247
return line ;
248
248
}
249
249
return (
@@ -260,7 +260,7 @@ export const CustomRichBlocks = ({
260
260
} ) ;
261
261
}
262
262
} else {
263
- return < > </ > ;
263
+ return null ;
264
264
}
265
265
} ) }
266
266
</ BlogParagraphContainer >
Original file line number Diff line number Diff line change
1
+ import type { ReactElement } from 'react' ;
2
+ import { createElement , Fragment } from 'react' ;
3
+
4
+ const newlineToBr = ( str : unknown ) : ( string | ReactElement ) [ ] => {
5
+ if ( typeof str !== 'string' ) {
6
+ return [ String ( str ) ] ;
7
+ }
8
+
9
+ return str . split ( / ( \r \n | \r | \n ) / g) . map ( ( line , index ) => {
10
+ if ( line . match ( / ( \r \n | \r | \n ) / g) ) {
11
+ return createElement ( 'br' , { key : index } ) ;
12
+ }
13
+ return createElement ( Fragment , { key : index } , line ) ;
14
+ } ) ;
15
+ } ;
16
+
17
+ export default newlineToBr ;
Original file line number Diff line number Diff line change @@ -9520,7 +9520,6 @@ __metadata:
9520
9520
react-dom : " npm:^18.3.1"
9521
9521
react-error-boundary : " npm:^4.0.13"
9522
9522
react-i18next : " npm:^15.0.1"
9523
- react-nl2br : " npm:^1.0.4"
9524
9523
react-router-dom : " npm:^6.26.0"
9525
9524
rollup-plugin-polyfill-node : " npm:^0.13.0"
9526
9525
sharp : " npm:^0.33.4"
@@ -11306,15 +11305,6 @@ __metadata:
11306
11305
languageName : node
11307
11306
linkType : hard
11308
11307
11309
- " react-nl2br@npm:^1.0.4 " :
11310
- version : 1.0.4
11311
- resolution : " react-nl2br@npm:1.0.4"
11312
- peerDependencies :
11313
- react : ^15.7.0 || ^16.14.0 || ^17.0.0 || ^18.0.0
11314
- checksum : 10/face38b19bec9ae9bf43e7efbf158a577f0810fd8d93650c464bdd80a37d61be6f59170cca4fe4993b44c8d5652c541d4f4786d30297ca3252fd99143b5b3816
11315
- languageName : node
11316
- linkType : hard
11317
-
11318
11308
" react-router-dom@npm:^6.26.0 " :
11319
11309
version : 6.26.1
11320
11310
resolution : " react-router-dom@npm:6.26.1"
You can’t perform that action at this time.
0 commit comments