File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
src/components/interactive-code-block Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import "./syntax-highlighting.css"
9
9
10
10
interface ResultViewerProps {
11
11
value ?: string
12
+ vainlyExtractData ?: boolean
12
13
}
13
14
14
15
/**
@@ -59,11 +60,23 @@ export class ResultViewer extends Component<ResultViewerProps> {
59
60
componentDidUpdate ( ) {
60
61
if ( ! this . view ) return
61
62
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
+
62
75
this . view . dispatch ( {
63
76
changes : {
64
77
from : 0 ,
65
78
to : this . view . state . doc . length ,
66
- insert : this . props . value || "" ,
79
+ insert : value ,
67
80
} ,
68
81
} )
69
82
}
You can’t perform that action at this time.
0 commit comments