File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,34 @@ function ansiToInlineStyle(text) {
38
38
}
39
39
40
40
function inlineBundleToReact ( bundle , key ) {
41
+ const children = bundle . content . split ( ' ' ) . reduce (
42
+ ( result , word ) => {
43
+ // If word is a URL
44
+ if ( / [ - a - z A - Z 0 - 9 @ : % . _ \+ ~ # = ] { 2 , 256 } \. [ a - z ] { 2 , 6 } \b ( [ - a - z A - Z 0 - 9 @ : % _ \+ . ~ # ? & / / = ] * ) / . test ( word ) ) {
45
+ return [
46
+ ...result ,
47
+ React . createElement ( 'a' , {
48
+ href : word ,
49
+ target : '_blank'
50
+ } , `${ word } ` )
51
+ ] ;
52
+ }
53
+ const lastWord = result . pop ( ) ;
54
+ if ( lastWord ) {
55
+ // If lastWord is a `<a>` element
56
+ if ( lastWord . type ) return [ ...result , lastWord , word ] ;
57
+ // If not, combine lastWord and word into single string
58
+ return [ ...result , [ lastWord , word ] . join ( ' ' ) ] ;
59
+ }
60
+ // If there is no lastWord because word is the first
61
+ return [ ...result , word ] ;
62
+ } ,
63
+ [ ]
64
+ ) ;
41
65
return React . createElement ( 'span' , {
42
66
style : bundle . style ,
43
67
key,
44
- } , bundle . content ) ;
68
+ } , children ) ;
45
69
}
46
70
47
71
function Ansi ( props ) {
You can’t perform that action at this time.
0 commit comments