summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/js/extra.js14
-rw-r--r--public/js/index.js9
-rw-r--r--public/js/pretty.js9
-rw-r--r--public/js/syncscroll.js4
4 files changed, 21 insertions, 15 deletions
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 = $('<div>' + code + '</div>');
- //prevent XSS
- result.find("script").replaceWith(function () {
- return "<noscript>" + $(this).html() + "</noscript>"
- });
- result.find("iframe").replaceWith(function () {
- return "<noiframe>" + $(this).html() + "</noiframe>"
- });
//link should open in new window or tab
result.find('a:not([href^="#"]):not([target])').attr('target', '_blank');
//update continue line numbers
@@ -576,11 +569,11 @@ function autoLinkify(view) {
}
function deduplicatedHeaderId(view) {
- var headers = view.find(':header').toArray();
+ var headers = view.find(':header.raw').removeClass('raw').toArray();
for (var i = 0; i < headers.length; i++) {
var id = $(headers[i]).attr('id');
if (!id) continue;
- var duplicatedHeaders = view.find(':header[id=' + id + ']').toArray();
+ var duplicatedHeaders = view.find(':header[id="' + id + '"]').toArray();
for (var j = 0; j < duplicatedHeaders.length; j++) {
if (duplicatedHeaders[j] != headers[i]) {
var newId = id + j;
@@ -685,6 +678,9 @@ md.renderer.rules.list_item_open = function ( /* tokens, idx, options, env */ )
md.renderer.rules.blockquote_open = function (tokens, idx /*, options, env */ ) {
return '<blockquote class="raw">\n';
};
+md.renderer.rules.heading_open = function (tokens, idx) {
+ return '<h' + tokens[idx].hLevel + ' class="raw">';
+};
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 = $('<textarea/>').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 '<h' + tokens[idx].hLevel + ' class="part" data-startline="' + startline + '" data-endline="' + endline + '">';
+ return '<h' + tokens[idx].hLevel + ' class="part raw" data-startline="' + startline + '" data-endline="' + endline + '">';
}
- return '<h' + tokens[idx].hLevel + '>';
+ return '<h' + tokens[idx].hLevel + ' class="raw">';
};
md.renderer.rules.fence = function (tokens, idx, options, env, self) {