From 898028d1a5097a7ac59d275a5d795e81ed60804d Mon Sep 17 00:00:00 2001 From: Jono Date: Mon, 16 Oct 2017 15:11:01 -0700 Subject: [PATCH] Removing '$ ' from each line of input before executing code blocks Signed-off-by: Jono --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 27fff0d..3f1811f 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,14 @@ import 'xterm/dist/xterm.css' var actions = document.querySelectorAll('code[class*="'+termName+'"]'); for (var n=0; n < actions.length; ++n) { actions[n].onclick = function() { - self.socket.emit('terminal in', instance.name, this.innerText); + + // get rid of first line bash prompt + var cmds = this.innerText.replace(/^\s*\$\s/, '') + + // get rid of later line bash prompts + cmds = cmds.replace(/(\r?\n\s*)\$\s/g, '$1') + + self.socket.emit('terminal in', instance.name, cmds); }; } }