From d3b4926ea80f412d8225d2bc17c0f991bb70d4d6 2013-04-06 19:14:51
From: Min RK <benjaminrk@gmail.com>
Date: 2013-04-06 19:14:51
Subject: [PATCH] Merge pull request #3136 from jfeser/8b94eddb4d15ce6f0c98675116d4609bdaaf99d9

Strip useless ANSI escape codes in notebook

ANSI color escape codes get handled specially by the notebook, but other kinds of codes just get printed out. Strip these codes out of the notebook output.

closes #2385
---

diff --git a/IPython/frontend/html/notebook/static/js/utils.js b/IPython/frontend/html/notebook/static/js/utils.js
index e1bcaa7..d94c40a 100644
--- a/IPython/frontend/html/notebook/static/js/utils.js
+++ b/IPython/frontend/html/notebook/static/js/utils.js
@@ -174,6 +174,12 @@ IPython.utils = (function (IPython) {
         var cmds = [];
         var opener = "";
         var closer = "";
+
+        // Strip all ANSI codes that are not color related.  Matches
+        // all ANSI codes that do not end with "m".
+        var ignored_re = /(?=(\033\[[\d;=]*[a-ln-zA-Z]{1}))\1(?!m)/g;
+        txt = txt.replace(ignored_re, "");
+
         while (re.test(txt)) {
             var cmds = txt.match(re)[1].split(";");
             closer = opened?"</span>":"";