From 8644a15a6b34a63313e38485618174ba0839c413 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 1 Aug 2017 12:06:34 -0700 Subject: [PATCH 1/2] Prevent marked from returning inline styles for table cells --- notebook/static/notebook/js/outputarea.js | 11 ++++++++++- notebook/static/notebook/js/textcell.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index 71c7b5726..95e641281 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -701,7 +701,16 @@ define([ var text_and_math = mathjaxutils.remove_math(markdown); var text = text_and_math[0]; var math = text_and_math[1]; - marked(text, function (err, html) { + // Prevent marked from returning inline styles for table cells + var renderer = new marked.Renderer(); + renderer.tablecell = function (content, flags) { + var type = flags.header ? 'th' : 'td'; + var start_tag = '<' + type + '>'; + var end_tag = '\n'; + return start_tag + content + end_tag; + }; + marked(text, { renderer: renderer }, function (err, html) { + // marked(text, function (err, html) { html = mathjaxutils.replace_math(html, math); toinsert.append(html); }); diff --git a/notebook/static/notebook/js/textcell.js b/notebook/static/notebook/js/textcell.js index 85425cfc8..a49b938be 100644 --- a/notebook/static/notebook/js/textcell.js +++ b/notebook/static/notebook/js/textcell.js @@ -391,7 +391,16 @@ define([ var text_and_math = mathjaxutils.remove_math(text); text = text_and_math[0]; math = text_and_math[1]; - marked(text, function (err, html) { + // Prevent marked from returning inline styles for table cells + var renderer = new marked.Renderer(); + renderer.tablecell = function (content, flags) { + var type = flags.header ? 'th' : 'td'; + var start_tag = '<' + type + '>'; + var end_tag = '\n'; + return start_tag + content + end_tag; + }; + marked(text, { renderer: renderer }, function (err, html) { + // marked(text, function (err, html) { html = mathjaxutils.replace_math(html, math); html = security.sanitize_html(html); html = $($.parseHTML(html)); From 4ac086d477ec9790513441565bd65e2ae4fcd8fb Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Wed, 2 Aug 2017 06:57:36 -0700 Subject: [PATCH 2/2] Remove commented out old code --- notebook/static/notebook/js/outputarea.js | 1 - notebook/static/notebook/js/textcell.js | 1 - 2 files changed, 2 deletions(-) diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index 95e641281..e9e4d3ffd 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -710,7 +710,6 @@ define([ return start_tag + content + end_tag; }; marked(text, { renderer: renderer }, function (err, html) { - // marked(text, function (err, html) { html = mathjaxutils.replace_math(html, math); toinsert.append(html); }); diff --git a/notebook/static/notebook/js/textcell.js b/notebook/static/notebook/js/textcell.js index a49b938be..f70abd089 100644 --- a/notebook/static/notebook/js/textcell.js +++ b/notebook/static/notebook/js/textcell.js @@ -400,7 +400,6 @@ define([ return start_tag + content + end_tag; }; marked(text, { renderer: renderer }, function (err, html) { - // marked(text, function (err, html) { html = mathjaxutils.replace_math(html, math); html = security.sanitize_html(html); html = $($.parseHTML(html));