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"
99
1010interface 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 }
You can’t perform that action at this time.
0 commit comments