Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit f35d261

Browse files
committed
fix: <Ansi/> component has empty links, and clicks bubble up
1 parent 2b202d2 commit f35d261

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/plugin-client-common/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"@patternfly/react-table": "4.111.4",
3030
"anser": "2.1.1",
3131
"ansi-regex": "6.0.1",
32-
"strip-ansi": "6.0.1",
3332
"html-entities": "2.3.3",
3433
"madwizard": ">=1.6.4",
3534
"monaco-editor": "0.34.0",

plugins/plugin-client-common/src/components/Content/Scalar/Ansi.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import React from 'react'
1818
import ansiRegex from 'ansi-regex'
19-
import stripAnsi from 'strip-ansi'
2019
import { ansiToJson, AnserJsonEntry } from 'anser'
2120

2221
const Markdown = React.lazy(() => import('../Markdown'))
@@ -45,6 +44,11 @@ function classOf(entry: AnserJsonEntry) {
4544
return `${fg} ${bg} ${deco.join(' ')}`
4645
}
4746

47+
/** A stopPropagation onClick event handler */
48+
function stopProp(evt: React.MouseEvent) {
49+
evt.stopPropagation()
50+
}
51+
4852
function content(source: string) {
4953
if (/kuiexec/.test(source)) {
5054
// special case for embedded links; Markdown trims prefix and suffix whitespace
@@ -80,7 +84,12 @@ function content(source: string) {
8084
if (idx2 >= 0) {
8185
// the html anchor
8286
const text = source.slice(start2, idx2)
83-
A.push(<a href={stripAnsi(link)}>{text}</a>)
87+
const href = link.slice(5, link.length - 1) // `strip-ansi@6.0.1` doesn't seem to work here :(
88+
A.push(
89+
<a target="_blank" href={href} rel="noreferrer">
90+
{text}
91+
</a>
92+
)
8493

8594
start = idx2 + tail.length
8695
}
@@ -93,7 +102,11 @@ function content(source: string) {
93102
A.push(source.slice(start))
94103
}
95104

96-
return <span className="normal-wrap">{A}</span>
105+
return (
106+
<span onClick={stopProp} className="normal-wrap">
107+
{A}
108+
</span>
109+
)
97110
}
98111
return source
99112
}

0 commit comments

Comments
 (0)