@@ -40,11 +40,7 @@ import { KernelConnectionMetadata } from './kernels/types';
4040
4141// tslint:disable-next-line: no-require-imports
4242import cloneDeep = require( 'lodash/cloneDeep' ) ;
43- // tslint:disable-next-line: no-require-imports
44- import escape = require( 'lodash/escape' ) ;
45- // tslint:disable-next-line: no-require-imports
46- import unescape = require( 'lodash/unescape' ) ;
47- import { concatMultilineString , formatStreamText } from '../../../datascience-ui/common' ;
43+ import { concatMultilineString , formatStreamText , splitMultilineString } from '../../../datascience-ui/common' ;
4844import { RefBool } from '../../common/refBool' ;
4945import { PythonEnvironment } from '../../pythonEnvironments/info' ;
5046import { getInterpreterFromKernelConnectionMetadata , isPythonKernelConnection } from './kernels/helpers' ;
@@ -787,12 +783,12 @@ export class JupyterNotebookBase implements INotebook {
787783 outputs . forEach ( ( o ) => {
788784 if ( o . output_type === 'stream' ) {
789785 const stream = o as nbformat . IStream ;
790- result = result . concat ( formatStreamText ( unescape ( concatMultilineString ( stream . text , true ) ) ) ) ;
786+ result = result . concat ( formatStreamText ( concatMultilineString ( stream . text , true ) ) ) ;
791787 } else {
792788 const data = o . data ;
793789 if ( data && data . hasOwnProperty ( 'text/plain' ) ) {
794790 // tslint:disable-next-line:no-any
795- result = result . concat ( unescape ( ( data as any ) [ 'text/plain' ] ) ) ;
791+ result = result . concat ( ( data as any ) [ 'text/plain' ] ) ;
796792 }
797793 }
798794 } ) ;
@@ -1225,7 +1221,10 @@ export class JupyterNotebookBase implements INotebook {
12251221 ) {
12261222 // Check our length on text output
12271223 if ( msg . content . data && msg . content . data . hasOwnProperty ( 'text/plain' ) ) {
1228- msg . content . data [ 'text/plain' ] = escape ( trimFunc ( msg . content . data [ 'text/plain' ] as string ) ) ;
1224+ msg . content . data [ 'text/plain' ] = splitMultilineString (
1225+ // tslint:disable-next-line: no-any
1226+ trimFunc ( concatMultilineString ( msg . content . data [ 'text/plain' ] as any ) )
1227+ ) ;
12291228 }
12301229
12311230 this . addToCellData (
@@ -1253,14 +1252,14 @@ export class JupyterNotebookBase implements INotebook {
12531252 reply . payload . forEach ( ( o ) => {
12541253 if ( o . data && o . data . hasOwnProperty ( 'text/plain' ) ) {
12551254 // tslint:disable-next-line: no-any
1256- const str = ( o . data as any ) [ 'text/plain' ] . toString ( ) ;
1257- const data = escape ( trimFunc ( str ) ) as string ;
1255+ const str = concatMultilineString ( ( o . data as any ) [ 'text/plain' ] ) ; // NOSONAR
1256+ const data = trimFunc ( str ) ;
12581257 this . addToCellData (
12591258 cell ,
12601259 {
12611260 // Mark as stream output so the text is formatted because it likely has ansi codes in it.
12621261 output_type : 'stream' ,
1263- text : data ,
1262+ text : splitMultilineString ( data ) ,
12641263 name : 'stdout' ,
12651264 metadata : { } ,
12661265 execution_count : reply . execution_count
@@ -1302,23 +1301,25 @@ export class JupyterNotebookBase implements INotebook {
13021301 ? data . outputs [ data . outputs . length - 1 ]
13031302 : undefined ;
13041303 if ( existing ) {
1305- // tslint:disable-next-line:restrict-plus-operands
1306- existing . text = existing . text + escape ( msg . content . text ) ;
1307- const originalText = formatStreamText ( concatMultilineString ( existing . text ) ) ;
1304+ const originalText = formatStreamText (
1305+ // tslint:disable-next-line: no-any
1306+ `${ concatMultilineString ( existing . text as any ) } ${ concatMultilineString ( msg . content . text ) } `
1307+ ) ;
13081308 originalTextLength = originalText . length ;
1309- existing . text = trimFunc ( originalText ) ;
1310- trimmedTextLength = existing . text . length ;
1309+ const newText = trimFunc ( originalText ) ;
1310+ trimmedTextLength = newText . length ;
1311+ existing . text = splitMultilineString ( newText ) ;
13111312 } else {
1312- const originalText = formatStreamText ( concatMultilineString ( escape ( msg . content . text ) ) ) ;
1313+ const originalText = formatStreamText ( concatMultilineString ( msg . content . text ) ) ;
13131314 originalTextLength = originalText . length ;
13141315 // Create a new stream entry
13151316 const output : nbformat . IStream = {
13161317 output_type : 'stream' ,
13171318 name : msg . content . name ,
1318- text : trimFunc ( originalText )
1319+ text : [ trimFunc ( originalText ) ]
13191320 } ;
13201321 data . outputs = [ ...data . outputs , output ] ;
1321- trimmedTextLength = output . text . length ;
1322+ trimmedTextLength = output . text [ 0 ] . length ;
13221323 cell . data = data ;
13231324 }
13241325
@@ -1327,23 +1328,16 @@ export class JupyterNotebookBase implements INotebook {
13271328 // the output is trimmed and what setting changes that.
13281329 // * If data.metadata.tags is undefined, define it so the following
13291330 // code is can rely on it being defined.
1330- if ( data . metadata . tags === undefined ) {
1331- data . metadata . tags = [ ] ;
1332- }
1333-
1334- data . metadata . tags = data . metadata . tags . filter ( ( t ) => t !== 'outputPrepend' ) ;
1335-
13361331 if ( trimmedTextLength < originalTextLength ) {
1332+ if ( data . metadata . tags === undefined ) {
1333+ data . metadata . tags = [ ] ;
1334+ }
1335+ data . metadata . tags = data . metadata . tags . filter ( ( t ) => t !== 'outputPrepend' ) ;
13371336 data . metadata . tags . push ( 'outputPrepend' ) ;
13381337 }
13391338 }
13401339
13411340 private handleDisplayData ( msg : KernelMessage . IDisplayDataMsg , clearState : RefBool , cell : ICell ) {
1342- // Escape text output
1343- if ( msg . content . data && msg . content . data . hasOwnProperty ( 'text/plain' ) ) {
1344- msg . content . data [ 'text/plain' ] = escape ( msg . content . data [ 'text/plain' ] as string ) ;
1345- }
1346-
13471341 const output : nbformat . IDisplayData = {
13481342 output_type : 'display_data' ,
13491343 data : msg . content . data ,
@@ -1391,10 +1385,14 @@ export class JupyterNotebookBase implements INotebook {
13911385 private handleError ( msg : KernelMessage . IErrorMsg , clearState : RefBool , cell : ICell ) {
13921386 const output : nbformat . IError = {
13931387 output_type : 'error' ,
1394- ename : escape ( msg . content . ename ) ,
1395- evalue : escape ( msg . content . evalue ) ,
1396- traceback : msg . content . traceback . map ( escape )
1388+ ename : msg . content . ename ,
1389+ evalue : msg . content . evalue ,
1390+ traceback : msg . content . traceback
13971391 } ;
1392+ if ( msg . content . hasOwnProperty ( 'transient' ) ) {
1393+ // tslint:disable-next-line: no-any
1394+ output . transient = ( msg . content as any ) . transient ;
1395+ }
13981396 this . addToCellData ( cell , output , clearState ) ;
13991397 cell . state = CellState . error ;
14001398
0 commit comments