summaryrefslogtreecommitdiff
path: root/public/js/extra.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/extra.js')
-rw-r--r--public/js/extra.js88
1 files changed, 64 insertions, 24 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index 4a6c4a67..af43c2b2 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -1,3 +1,8 @@
+var hljs = require('highlight.js');
+var PDFObject = require('pdfobject');
+var S = require('string');
+var saveAs = require('file-saver').saveAs;
+
//auto update last change
var createtime = null;
var lastchangetime = null;
@@ -242,7 +247,7 @@ function finishView(view) {
});
//emojify
try {
- emojify.run(view[0]);
+ emojify.run(view[0]);
} catch (err) {
console.warn(err);
}
@@ -263,12 +268,12 @@ function finishView(view) {
try {
var $value = $(value);
var $ele = $(value).parent().parent();
-
+
var sequence = $value;
sequence.sequenceDiagram({
theme: 'simple'
});
-
+
$ele.addClass('sequence-diagram');
$value.children().unwrap().unwrap();
var svg = $ele.find('> svg');
@@ -284,7 +289,7 @@ function finishView(view) {
try {
var $value = $(value);
var $ele = $(value).parent().parent();
-
+
var chart = flowchart.parse($value.text());
$value.html('');
chart.drawSVG(value, {
@@ -293,7 +298,7 @@ function finishView(view) {
'font-size': '16px',
'font-family': "'Andale Mono', monospace"
});
-
+
$ele.addClass('flow-chart');
$value.children().unwrap().unwrap();
} catch (err) {
@@ -306,28 +311,29 @@ function finishView(view) {
try {
var $value = $(value);
var $ele = $(value).parent().parent();
-
+
var graphviz = Viz($value.text());
$value.html(graphviz);
-
+
$ele.addClass('graphviz');
$value.children().unwrap().unwrap();
} catch (err) {
console.warn(err);
}
});
+
//mermaid
var mermaids = view.find(".mermaid.raw").removeClass("raw");
mermaids.each(function (key, value) {
try {
var $value = $(value);
var $ele = $(value).parent().parent();
-
+
var mermaidError = null;
mermaid.parseError = function (err, hash) {
mermaidError = err;
};
-
+
if (mermaidAPI.parse($value.text())) {
$ele.addClass('mermaid');
$ele.html($value.text());
@@ -483,6 +489,7 @@ function postProcess(code) {
}
return result;
}
+window.postProcess = postProcess;
function generateCleanHTML(view) {
var src = view.clone();
@@ -534,6 +541,8 @@ function exportToRawHTML(view) {
saveAs(blob, filename);
}
+var common = require('./common.js');
+var serverurl = common.serverurl;
//extract markdown body to html and compile to template
function exportToHTML(view) {
var title = renderTitle(ui.area.markdown);
@@ -829,7 +838,10 @@ emojify.setConfig({
ignore_emoticons: true
});
-var md = window.markdownit('default', {
+var markdownit = require('markdown-it');
+var markdownitContainer = require('markdown-it-container');
+
+var md = markdownit('default', {
html: true,
breaks: true,
langPrefix: "",
@@ -837,25 +849,28 @@ var md = window.markdownit('default', {
typographer: true,
highlight: highlightRender
});
-md.use(window.markdownitAbbr);
-md.use(window.markdownitFootnote);
-md.use(window.markdownitDeflist);
-md.use(window.markdownitMark);
-md.use(window.markdownitIns);
-md.use(window.markdownitSub);
-md.use(window.markdownitSup);
-md.use(window.markdownitMathjax);
-md.use(window.markdownitImsize);
+window.md = md;
+
+md.use(require('markdown-it-abbr'));
+md.use(require('markdown-it-footnote'));
+md.use(require('markdown-it-deflist'));
+md.use(require('markdown-it-mark'));
+md.use(require('markdown-it-ins'));
+md.use(require('markdown-it-sub'));
+md.use(require('markdown-it-sup'));
+md.use(require('../vendor/markdown-it-mathjax'));
+md.use(require('markdown-it-imsize'));
+
function renderContainer(tokens, idx, options, env, self) {
tokens[idx].attrJoin('role', 'alert');
tokens[idx].attrJoin('class', 'alert');
tokens[idx].attrJoin('class', 'alert-' + tokens[idx].info.trim());
return self.renderToken.apply(self, arguments);
}
-md.use(window.markdownitContainer, 'success', { render: renderContainer });
-md.use(window.markdownitContainer, 'info', { render: renderContainer });
-md.use(window.markdownitContainer, 'warning', { render: renderContainer });
-md.use(window.markdownitContainer, 'danger', { render: renderContainer });
+md.use(markdownitContainer, 'success', { render: renderContainer });
+md.use(markdownitContainer, 'info', { render: renderContainer });
+md.use(markdownitContainer, 'warning', { render: renderContainer });
+md.use(markdownitContainer, 'danger', { render: renderContainer });
md.renderer.rules.image = function (tokens, idx, options, env, self) {
tokens[idx].attrJoin('class', 'raw');
@@ -900,6 +915,9 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) {
+ '</code></pre>\n';
};
+/* Defined regex markdown it plugins */
+require('script!../vendor/markdown-it-regexp');
+
//youtube
var youtubePlugin = new Plugin(
// regexp to match
@@ -1046,4 +1064,26 @@ md.use(gistPlugin);
md.use(tocPlugin);
md.use(slidesharePlugin);
md.use(speakerdeckPlugin);
-md.use(pdfPlugin); \ No newline at end of file
+md.use(pdfPlugin);
+
+module.exports = {
+ md: md,
+ createtime: createtime,
+ lastchangetime: lastchangetime,
+ updateLastChange: updateLastChange,
+ lastchangeui: lastchangeui,
+ lastchangeuser: lastchangeuser,
+ postProcess: postProcess,
+ finishView: finishView,
+ autoLinkify: autoLinkify,
+ deduplicatedHeaderId: deduplicatedHeaderId,
+ renderTOC: renderTOC,
+ renderTitle: renderTitle,
+ renderFilename: renderFilename,
+ generateToc: generateToc,
+ smoothHashScroll: smoothHashScroll,
+ scrollToHash: scrollToHash,
+ owner: owner,
+ updateLastChangeUser: updateLastChangeUser,
+ updateOwner: updateOwner
+};