@@ -74,28 +74,39 @@ async function send(conversation, action) {
7474}
7575
7676function parseContent ( content , valueType ) {
77- let parsedContent ;
77+ let regex ;
78+
79+ // Define the regular expression based on the valueType
80+ switch ( valueType ) {
81+ case 'json' :
82+ regex = / ` ` ` j s o n \n ( [ \s \S ] * ?) \n ` ` ` / ;
83+ break ;
84+ case 'javascript' :
85+ regex = / ` ` ` j a v a s c r i p t \n ( [ \s \S ] * ?) \n ` ` ` / ;
86+ break ;
87+ case 'html' :
88+ regex = / ` ` ` h t m l \n ( [ \s \S ] * ?) \n ` ` ` / ;
89+ break ;
90+ case 'css' :
91+ regex = / ` ` ` c s s \n ( [ \s \S ] * ?) \n ` ` ` / ;
92+ break ;
93+ default :
94+ break ;
95+ }
96+
97+ // Extract the relevant section using the regular expression
98+ if ( regex ) {
99+ const match = content . match ( regex ) ;
100+ if ( match && match [ 1 ] ) {
101+ content = match [ 1 ] . trim ( ) ; // Extracted content between the code block markers
102+ }
103+ }
78104
79105 if ( valueType === 'json' ) {
80- content = content . replace ( / ` ` ` j s o n \n | \n ` ` ` / g, '' ) ;
81- parsedContent = JSON . parse ( content ) ;
82- } else if ( valueType === 'javascript' ) {
83- content = content . replace ( / ` ` ` j a v a s c r i p t \n | \n ` ` ` / g, '' ) ;
84- parsedContent = content ;
85- } else if ( valueType === 'html' ) {
86- content = content . replace ( / ` ` ` h t m l \n | \n ` ` ` / g, '' ) ;
87- parsedContent = content ;
88- } else if ( valueType === 'css' ) {
89- content = content . replace ( / ` ` ` c s s \n | \n ` ` ` / g, '' ) ;
90- parsedContent = content ;
91- } else if ( valueType === 'markdown' ) {
92- parsedContent = content ;
93- } else {
94- // Default case to handle any other types or plain text
95- parsedContent = content ;
106+ content = JSON . parse ( content ) ;
96107 }
97108
98- return parsedContent ;
109+ return content ;
99110}
100111
101112// Function to extract the object from the generated code
0 commit comments