summaryrefslogtreecommitdiff
path: root/public/js/extra.js
diff options
context:
space:
mode:
authorWu Cheng-Han2015-12-20 11:28:54 -0600
committerWu Cheng-Han2015-12-20 11:28:54 -0600
commit9eb23603f4d30a0822afde7fbd234976557f575a (patch)
tree51de9b06d232d37164c92b9cfdb65e550431da93 /public/js/extra.js
parent45ec05e2ed4962fcd4497cea8b58176f44a9ec3b (diff)
Added support of toc syntax
Diffstat (limited to 'public/js/extra.js')
-rw-r--r--public/js/extra.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index ef1f7e35..12342f09 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -341,6 +341,7 @@ function generateToc(id) {
'level': 3,
'top': -1,
'class': 'toc',
+ 'ulClass': 'nav',
'targetId': id
});
if (target.text() == 'undefined')
@@ -460,6 +461,26 @@ function deduplicatedHeaderId(view) {
}
}
+function renderTOC(view) {
+ var tocs = view.find('.toc').toArray();
+ for (var i = 0; i < tocs.length; i++) {
+ var toc = $(tocs[i]);
+ var id = 'toc' + i;
+ toc.attr('id', id);
+ var target = $('#' + id);
+ target.html('');
+ new Toc('doc', {
+ 'level': 3,
+ 'top': -1,
+ 'class': 'toc',
+ 'targetId': id
+ });
+ if (target.text() == 'undefined')
+ target.html('');
+ target.replaceWith(target.html());
+ }
+}
+
function scrollToHash() {
var hash = location.hash;
location.hash = "";
@@ -623,7 +644,18 @@ var mathjaxPlugin = new Plugin(
return '<span class="mathjax raw">' + match[0] + '</span>';
}
);
+//TOC
+var tocPlugin = new Plugin(
+ // regexp to match
+ /^\[TOC\]$/,
+
+ // this function will be called when something matches
+ function (match, utils) {
+ return '<div class="toc"></div>';
+ }
+);
md.use(youtubePlugin);
md.use(vimeoPlugin);
md.use(gistPlugin);
-md.use(mathjaxPlugin); \ No newline at end of file
+md.use(mathjaxPlugin);
+md.use(tocPlugin); \ No newline at end of file