Skip to content

Commit 7817cab

Browse files
committed
Vainly extract data
1 parent 319f8c4 commit 7817cab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/interactive-code-block/result-viewer.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "./syntax-highlighting.css"
99

1010
interface ResultViewerProps {
1111
value?: string
12+
vainlyExtractData?: boolean
1213
}
1314

1415
/**
@@ -59,11 +60,23 @@ export class ResultViewer extends Component<ResultViewerProps> {
5960
componentDidUpdate() {
6061
if (!this.view) return
6162

63+
let value = this.props.value || ""
64+
if (this.props.vainlyExtractData) {
65+
try {
66+
const json = JSON.parse(value)
67+
if (json && typeof json === "object" && "data" in json) {
68+
value = JSON.stringify(json.data, null, 2)
69+
}
70+
} catch {
71+
// ignore
72+
}
73+
}
74+
6275
this.view.dispatch({
6376
changes: {
6477
from: 0,
6578
to: this.view.state.doc.length,
66-
insert: this.props.value || "",
79+
insert: value,
6780
},
6881
})
6982
}

0 commit comments

Comments
 (0)