File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,12 +68,16 @@ export function shouldStripCodeFences(generationType?: string): boolean {
6868 * Falls back to the original text if stripping would leave nothing.
6969 */
7070export function stripCodeFences ( text : string ) : string {
71- if ( ! text . trimStart ( ) . startsWith ( '```' ) ) return text
72-
7371 const lines = text . split ( '\n' )
7472 const openingFence = lines . findIndex ( ( line ) => FENCE_LINE . test ( line ) )
7573 if ( openingFence === - 1 ) return text
7674
75+ // Anything non-blank ahead of the first fence means the response does not open
76+ // with one, so the backticks belong to the content.
77+ for ( let index = 0 ; index < openingFence ; index ++ ) {
78+ if ( lines [ index ] . trim ( ) !== '' ) return text
79+ }
80+
7781 let closingFence = - 1
7882 for ( let index = lines . length - 1 ; index > openingFence ; index -- ) {
7983 if ( FENCE_LINE . test ( lines [ index ] ) ) {
You can’t perform that action at this time.
0 commit comments