summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/extra.js33
-rw-r--r--public/js/history.js5
-rw-r--r--public/js/index.js2
-rw-r--r--public/js/pretty.js7
-rw-r--r--public/js/render.js1
-rwxr-xr-xpublic/js/reveal-markdown.js5
-rw-r--r--public/js/slide.js18
7 files changed, 45 insertions, 26 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index 05d00780..20ce1728 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -2,6 +2,8 @@ require('prismjs/themes/prism.css');
var Prism = require('prismjs');
require('prismjs/components/prism-wiki');
+require('prismjs/components/prism-haskell');
+require('prismjs/components/prism-go');
var hljs = require('highlight.js');
var PDFObject = require('pdfobject');
var S = require('string');
@@ -285,17 +287,6 @@ function finishView(view) {
if ($(value).children().length == 0)
$(value).gist(viewAjaxCallback);
});
- //mathjax
- var mathjaxdivs = view.find('span.mathjax.raw').removeClass("raw").toArray();
- try {
- if (mathjaxdivs.length > 1) {
- MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs]);
- MathJax.Hub.Queue(viewAjaxCallback);
- } else if (mathjaxdivs.length > 0) {
- MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs[0]]);
- MathJax.Hub.Queue(viewAjaxCallback);
- }
- } catch (err) {}
//sequence diagram
var sequences = view.find("div.sequence-diagram.raw").removeClass("raw");
sequences.each(function (key, value) {
@@ -484,6 +475,11 @@ function finishView(view) {
var result = {
value: code
};
+ } else if (reallang == "haskell" || reallang == "go") {
+ code = S(code).unescapeHTML().s;
+ var result = {
+ value: Prism.highlight(code, Prism.languages[reallang])
+ };
} else if (reallang == "tiddlywiki" || reallang == "mediawiki") {
code = S(code).unescapeHTML().s;
var result = {
@@ -502,6 +498,19 @@ function finishView(view) {
else langDiv.html(result.value);
}
});
+ //mathjax
+ var mathjaxdivs = view.find('span.mathjax.raw').removeClass("raw").toArray();
+ try {
+ if (mathjaxdivs.length > 1) {
+ MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs]);
+ MathJax.Hub.Queue(viewAjaxCallback);
+ } else if (mathjaxdivs.length > 0) {
+ MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs[0]]);
+ MathJax.Hub.Queue(viewAjaxCallback);
+ }
+ } catch (err) {
+ console.warn(err);
+ }
//render title
document.title = renderTitle(view);
}
@@ -895,7 +904,7 @@ emojify.setConfig({
elements: ['script', 'textarea', 'a', 'pre', 'code', 'svg'],
classes: ['no-emojify']
},
- img_dir: serverurl + '/vendor/emojify.js/dist/images/basic',
+ img_dir: serverurl + '/build/emojify.js/dist/images/basic',
ignore_emoticons: true
});
diff --git a/public/js/history.js b/public/js/history.js
index 390e38eb..6972f24c 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,4 +1,5 @@
var store = require('store');
+var S = require('string');
var common = require('./common');
var checkIfAuth = common.checkIfAuth;
@@ -337,6 +338,10 @@ function parseToHistory(list, notehistory, callback) {
notehistory[i].timestamp = timestamp.valueOf();
notehistory[i].fromNow = timestamp.fromNow();
notehistory[i].time = timestamp.format('llll');
+ // prevent XSS
+ notehistory[i].text = S(notehistory[i].text).escapeHTML().s;
+ notehistory[i].tags = (notehistory[i].tags && notehistory[i].tags.length > 0) ? S(notehistory[i].tags).escapeHTML().s.split(',') : [];
+ // add to list
if (notehistory[i].id && list.get('id', notehistory[i].id).length == 0)
list.add(notehistory[i]);
}
diff --git a/public/js/index.js b/public/js/index.js
index 35f63839..f49c9da1 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -213,7 +213,7 @@ var cursorMenuThrottle = 50;
var cursorActivityDebounce = 50;
var cursorAnimatePeriod = 100;
var supportContainers = ['success', 'info', 'warning', 'danger'];
-var supportCodeModes = ['javascript', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'coffeescript', 'yaml', 'pug', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile', 'tiddlywiki', 'mediawiki'];
+var supportCodeModes = ['javascript', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'haskell', 'coffeescript', 'yaml', 'pug', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile', 'tiddlywiki', 'mediawiki', 'go'];
var supportCharts = ['sequence', 'flow', 'graphviz', 'mermaid'];
var supportHeaders = [
{
diff --git a/public/js/pretty.js b/public/js/pretty.js
index b5c5ba8a..c1a471a1 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -4,9 +4,6 @@ require('../css/site.css');
require('highlight.js/styles/github-gist.css');
-/* other vendors plugin */
-var S = require('string');
-
var extra = require('./extra');
var md = extra.md;
var finishView = extra.finishView;
@@ -18,10 +15,11 @@ var smoothHashScroll = extra.smoothHashScroll;
var postProcess = extra.postProcess;
var updateLastChange = extra.updateLastChange;
var parseMeta = extra.parseMeta;
+var scrollToHash = extra.scrollToHash;
var preventXSS = require('./render').preventXSS;
var markdown = $("#doc.markdown-body");
-var text = S(markdown.html()).unescapeHTML().s;
+var text = markdown.text();
var lastMeta = md.meta;
md.meta = {};
var rendered = md.render(text);
@@ -117,6 +115,7 @@ $(window).resize(function () {
$(document).ready(function () {
windowResize();
generateScrollspy();
+ setTimeout(scrollToHash, 0);
//tooltip
$('[data-toggle="tooltip"]').tooltip();
});
diff --git a/public/js/render.js b/public/js/render.js
index 559530b0..a61fc8fb 100644
--- a/public/js/render.js
+++ b/public/js/render.js
@@ -1,5 +1,6 @@
// allow some attributes
var whiteListAttr = ['id', 'class', 'style'];
+window.whiteListAttr = whiteListAttr;
// allow link starts with '.', '/' and custom protocol with '://'
var linkRegex = /^([\w|-]+:\/\/)|^([\.|\/])+/;
// allow data uri, from https://gist.github.com/bgrins/6194623
diff --git a/public/js/reveal-markdown.js b/public/js/reveal-markdown.js
index ca22e09c..3c3e1f5b 100755
--- a/public/js/reveal-markdown.js
+++ b/public/js/reveal-markdown.js
@@ -286,7 +286,10 @@
nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex );
node.nodeValue = nodeValue;
while( matchesClass = mardownClassRegex.exec( classes ) ) {
- elementTarget.setAttribute( matchesClass[1], matchesClass[2] );
+ var name = matchesClass[1];
+ var value = matchesClass[2];
+ if (name.substr(0, 5) === 'data-' || whiteListAttr.indexOf(name) !== -1)
+ elementTarget.setAttribute( name, filterXSS.escapeAttrValue(value) );
}
return true;
}
diff --git a/public/js/slide.js b/public/js/slide.js
index b9521e64..fa4adcb5 100644
--- a/public/js/slide.js
+++ b/public/js/slide.js
@@ -1,9 +1,5 @@
require('../css/extra.css');
require('../css/site.css');
-require('../css/slide.css');
-
-/* other vendors plugin */
-var S = require('string');
var extraModule = require('./extra');
var md = extraModule.md;
@@ -12,8 +8,7 @@ var finishView = extraModule.finishView;
var preventXSS = require('./render').preventXSS;
-var body = $(".slides").html();
-$(".slides").html(S(body).unescapeHTML().s);
+var body = $(".slides").text();
createtime = lastchangeui.time.attr('data-createtime');
lastchangetime = lastchangeui.time.attr('data-updatetime');
@@ -47,8 +42,15 @@ var deps = [{
}
}, {
src: serverurl + '/js/reveal-markdown.js',
- condition: function() {
- return !!document.querySelector('[data-markdown]');
+ callback: function () {
+ var slideOptions = {
+ separator: '^(\r\n?|\n)---(\r\n?|\n)$',
+ verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
+ };
+ var slides = RevealMarkdown.slidify(body, slideOptions);
+ $(".slides").html(slides);
+ RevealMarkdown.initialize();
+ $(".slides").show();
}
}, {
src: serverurl + '/vendor/reveal.js/plugin/notes/notes.js',