From 772e0e95c82727e77a7fe2c50b8bef75170c01d6 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 11 Oct 2016 22:17:51 +0800 Subject: [PATCH] speed up html displaying Signed-off-by: Le Tan --- resources/template.html | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/resources/template.html b/resources/template.html index 0567380d..6b597de3 100644 --- a/resources/template.html +++ b/resources/template.html @@ -39,10 +39,17 @@ } }); - var markdownToHtml = function (markdown) { - return marked(markdown, { renderer: renderer }); + var markdownToHtml = function (markdown, needToc) { + toc = []; + if (needToc) { + var html = marked(markdown, { renderer: renderer }); + return html.replace(/

\[TOC\]<\/p>/ig, '

'); + } else { + return marked(markdown); + } }; + // Handle wrong title levels, such as '#' followed by '###' var toPerfectToc = function (toc) { var i; var curLevel = 1; @@ -67,6 +74,7 @@ return '' + item.title + ''; }; + // Turn a perfect toc to a tree using