From 16af51ad77aa95646b3dccabf93f04392874b251 Mon Sep 17 00:00:00 2001 From: Tjatse Date: Tue, 16 Dec 2014 14:22:04 +0800 Subject: [PATCH] Make sure tags are closed. --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 60efe86..cb90843 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ function ansiHTML(text){ // Cache opened sequence. var ansiCodes = []; // Replace with markup. - return text.replace(/\033\[(\d+)*m/g, function(match, seq){ + var ret = text.replace(/\033\[(\d+)*m/g, function(match, seq){ var ot = openTags[seq]; if (ot) { // If current sequence has been opened, close it. @@ -79,6 +79,12 @@ function ansiHTML(text){ } return ''; }); + + // Make sure tags are closed. + var l = ansiCodes.length; + (l > 0) && (ret += Array(l + 1).join('')); + + return ret; } /**