From fdc70185001d048a3a59ea6580066445148e2ab0 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Thu, 20 May 2021 14:52:30 +0200 Subject: [PATCH] terminal2 firstchild fix fix so tests will pass --- apps/remix-ide/src/app/panels/terminal.js | 35 +++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/panels/terminal.js b/apps/remix-ide/src/app/panels/terminal.js index e5fef96b7f..bd474b41fb 100644 --- a/apps/remix-ide/src/app/panels/terminal.js +++ b/apps/remix-ide/src/app/panels/terminal.js @@ -1,6 +1,7 @@ /* global Node, requestAnimationFrame */ import { Plugin } from '@remixproject/engine' import * as packageJson from '../../../../../package.json' +import * as remixBleach from '../../lib/remixBleach' var yo = require('yo-yo') var javascriptserialize = require('javascript-serialize') @@ -26,7 +27,7 @@ var ghostbar = yo`
` const profile = { displayName: 'Terminal', name: 'terminal', - methods: [], + methods: ['log'], events: [], description: ' - ', version: packageJson.version @@ -113,6 +114,32 @@ class Terminal extends Plugin { this.off('scriptRunner', 'error') } + log (message) { + var command = this.commands[message.type] + if (typeof command === 'function') { + if (typeof message.value === 'string' && message.type === 'html') { + var el = document.createElement('div') + el.innerHTML = remixBleach.sanitize(message.value, { + list: [ + 'a', + 'b', + 'p', + 'em', + 'strong', + 'div', + 'span', + 'ul', + 'li', + 'ol', + 'hr' + ] + }) + message.value = el + } + command(message.value) + }; + } + logHtml (html) { var command = this.commands.html if (typeof command === 'function') command(html) @@ -653,7 +680,11 @@ class Terminal extends Plugin { return function logger (args, scopedCommands, append) { var types = args.filter(filterUndefined).map(type) var values = javascriptserialize.apply(null, args.filter(filterUndefined)).map(function (val, idx) { - if (typeof args[idx] === 'string') val = args[idx] + if (typeof args[idx] === 'string') { + const el = document.createElement('div') + el.innerHTML = args[idx].replace(/(\r\n|\n|\r)/gm, '
') + val = el.children.length === 0 ? el.firstChild : el + } if (types[idx] === 'element') val = jsbeautify.html(val) return val })