From 8db142554fbe1c85aa8ffcdf0900b2855645939b Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Thu, 11 Feb 2016 14:35:25 -0600 Subject: Updated rendering operations to improve performance --- public/js/extra.js | 14 +++++--------- public/js/index.js | 9 +++++++-- public/js/pretty.js | 9 +++++++-- public/js/syncscroll.js | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) (limited to 'public') diff --git a/public/js/extra.js b/public/js/extra.js index a2ae83f6..28a91fbc 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -338,13 +338,6 @@ function finishView(view) { //only static transform should be here function postProcess(code) { var result = $('
\n'; }; +md.renderer.rules.heading_open = function (tokens, idx) { + return ''; +}; md.renderer.rules.fence = function (tokens, idx, options, env, self) { var token = tokens[idx]; var langClass = ''; diff --git a/public/js/index.js b/public/js/index.js index 2e797ac3..3507e016 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2132,10 +2132,15 @@ var lastResult = null; function updateViewInner() { if (currentMode == modeType.edit || !isDirty) return; var value = editor.getValue(); + var lastMeta = md.meta; md.meta = {}; - md.render(value); //only for get meta - parseMeta(md, ui.area.markdown, $('#toc'), $('#toc-affix')); var rendered = md.render(value); + // only render again when meta changed + if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) { + parseMeta(md, ui.area.markdown, $('#toc'), $('#toc-affix')); + rendered = md.render(value); + } + // prevent XSS rendered = preventXSS(rendered); var result = postProcess(rendered).children().toArray(); partialUpdate(result, lastResult, ui.area.markdown.children().toArray()); diff --git a/public/js/pretty.js b/public/js/pretty.js index a38dc244..40d90cf7 100644 --- a/public/js/pretty.js +++ b/public/js/pretty.js @@ -1,9 +1,14 @@ var markdown = $(".markdown-body"); var text = $('').html(markdown.html()).text(); +var lastMeta = md.meta; md.meta = {}; -md.render(text); //only for get meta -parseMeta(md, markdown, $('#toc'), $('#toc-affix')); var rendered = md.render(text); +// only render again when meta changed +if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) { + parseMeta(md, markdown, $('#toc'), $('#toc-affix')); + rendered = md.render(text); +} +// prevent XSS rendered = preventXSS(rendered); var result = postProcess(rendered); markdown.html(result.html()); diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index c3793a88..abc9a274 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -73,9 +73,9 @@ md.renderer.rules.heading_open = function (tokens, idx) { if (tokens[idx].lines && tokens[idx].level === 0) { var startline = tokens[idx].lines[0] + 1; var endline = tokens[idx].lines[1]; - return ' '; + return ' '; } - return ' '; + return ' '; }; md.renderer.rules.fence = function (tokens, idx, options, env, self) { -- cgit v1.2.3