From d979f4beddce05d7091c2d6439fb031aeee41f2a Mon Sep 17 00:00:00 2001 From: MinRK Date: Thu, 11 Sep 2014 12:08:35 -0700 Subject: [PATCH] better regex replacement for MarkdownCell.set_heading_level (c/o Matthias) --- IPython/html/static/notebook/js/textcell.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 61db7af6c..183db4014 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -226,16 +226,9 @@ define([ // make a markdown cell a heading level = level || 1; var source = this.get_text(); - // \s\S appears to be the js version of multi-line dot-all - var match = source.match(/(#*)\s*([\s\S]*)/); - // strip the leading `#` if it's already there - if (match) { - source = match[2]; - } - // add `#` markdown heading prefix - var new_text = new Array(level + 1).join('#') + ' ' + source; - - this.set_text(new_text); + source = source.replace(/^(#*)\s?/, + new Array(level + 1).join('#') + ' '); + this.set_text(source); this.refresh(); if (this.rendered) { this.render();