import * as vscode from 'vscode' ; import { SnapshotMetadata } from 'jest-editor-support' ; import { extensionName } from '../appGlobals' ; export const previewCommand = `${ extensionName }.snapshot.preview` ; export function registerSnapshotPreview ( ) { let panel = null ; const escaped = ( snapshot ) => { if ( snapshot ) { const escaped = snapshot . replace ( /&/g , '&amp;' ) . replace ( /"/g , '&quot;' ) . replace ( /'/g , '&#39;' ) . replace ( /</g , '&lt;' ) . replace ( />/g , '&gt;' ) ; return `<pre>${ escaped }</pre>` ; } } ; return [ vscode . commands . registerCommand ( previewCommand , ( snapshot ) => { if ( panel ) { panel . reveal ( ) ; } else { panel = vscode . window . createWebviewPanel ( 'view_snapshot' , snapshot . name , vscode . ViewColumn . Two , { } ) ; panel . onDidDispose ( ( ) => { panel = null ; } ) ; } panel . webview . html = ( snapshot . content && escaped ( snapshot . content ) ) || '' ; panel . title = snapshot . name ; } ) , ] ; }