##// END OF EJS Templates
Fix ansispan() to ignore stray [0m
Mateusz Paprocki -
Show More
@@ -284,27 +284,36 b' define(['
284 284 function ansispan(str) {
285 285 // ansispan function adapted from github.com/mmalecki/ansispan (MIT License)
286 286 // regular ansi escapes (using the table above)
287 var is_open = false
287 288 return str.replace(/\033\[(0?[01]|22|39)?([;\d]+)?m/g, function(match, prefix, pattern) {
288 289 if (!pattern) {
289 290 // [(01|22|39|)m close spans
290 return "</span>";
291 }
292 // consume sequence of color escapes
293 var numbers = pattern.match(/\d+/g);
294 var attrs = {};
295 while (numbers.length > 0) {
296 _process_numbers(attrs, numbers);
297 }
298
299 var span = "<span ";
300 for (var attr in attrs) {
301 var value = attrs[attr];
302 span = span + " " + attr + '="' + attrs[attr] + '"';
291 if (is_open) {
292 is_open = false;
293 return "</span>";
294 } else {
295 return "";
296 }
297 } else {
298 is_open = true;
299
300 // consume sequence of color escapes
301 var numbers = pattern.match(/\d+/g);
302 var attrs = {};
303 while (numbers.length > 0) {
304 _process_numbers(attrs, numbers);
305 }
306
307 var span = "<span ";
308 for (var attr in attrs) {
309 var value = attrs[attr];
310 span = span + " " + attr + '="' + attrs[attr] + '"';
311 }
312 return span + ">";
303 313 }
304 return span + ">";
305 314 });
306 315 };
307
316
308 317 // Transform ANSI color escape codes into HTML <span> tags with css
309 318 // classes listed in the above ansi_colormap object. The actual color used
310 319 // are set in the css file.
General Comments 0
You need to be logged in to leave comments. Login now