7
7
} from ' @/components/visualizations/TableVisualization/tableVizToolbar'
8
8
import { Ast } from ' @/util/ast'
9
9
import { Pattern } from ' @/util/ast/match'
10
+ import { LINKABLE_URL_REGEX } from ' @/util/link'
10
11
import { useVisualizationConfig } from ' @/util/visualizationBuiltins'
11
12
import type {
12
13
CellClassParams ,
@@ -197,7 +198,8 @@ function formatText(params: ICellRendererParams) {
197
198
.replaceAll (' >' , ' >' )
198
199
199
200
if (textFormatterSelected .value === ' off' ) {
200
- return htmlEscaped .replace (/ ^ \s + | \s + $ / g , ' ' )
201
+ const replaceLinks = replaceLinksWithTag (htmlEscaped )
202
+ return replaceLinks .replace (/ ^ \s + | \s + $ / g , ' ' )
201
203
}
202
204
203
205
const partialMappings = {
@@ -218,10 +220,7 @@ function formatText(params: ICellRendererParams) {
218
220
return ` <span style="color: #df8800">${match .replaceAll (' ' , ' ·' )}</span> `
219
221
})
220
222
221
- const replaceLinks = replaceSpaces .replace (
222
- / https? :\/\/ ([-()_. !~*';/?:@&=+$,A-Za-z0-9 ] )+ / g ,
223
- (url : string ) => ` <a href="${url }" target="_blank" class="link">${url }</a> ` ,
224
- )
223
+ const replaceLinks = replaceLinksWithTag (replaceSpaces )
225
224
226
225
const replaceReturns = replaceLinks .replace (
227
226
/ \r\n / g ,
@@ -251,6 +250,13 @@ function setRowLimit(newRowLimit: number) {
251
250
}
252
251
}
253
252
253
+ function replaceLinksWithTag(str : string ) {
254
+ return str .replace (
255
+ LINKABLE_URL_REGEX ,
256
+ (url : string ) => ` <a href="${url }" target="_blank" class="link">${url }</a> ` ,
257
+ )
258
+ }
259
+
254
260
function escapeHTML(str : string ) {
255
261
const mapping: Record <string , string > = {
256
262
' &' : ' &' ,
@@ -438,10 +444,7 @@ function toLinkField(fieldName: string, options: LinkFieldOptions = {}): ColDef
438
444
params .node ?.rowPinned === ' top' ?
439
445
null
440
446
: ` Double click to view this ${tooltipValue ?? ' value' } in a separate component ` ,
441
- cellRenderer : (params : ICellRendererParams ) =>
442
- params .node .rowPinned === ' top' ?
443
- ` <div> ${params .value }</div> `
444
- : ` <div class='link'> ${params .value } </div> ` ,
447
+ cellRenderer : (params : ICellRendererParams ) => ` <div class='link'> ${params .value } </div> ` ,
445
448
}
446
449
}
447
450
0 commit comments