PlantUML integration
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
"rss": true,
|
||||
"webhook": true,
|
||||
"prism": true,
|
||||
"mathjax": true
|
||||
"mathjax": true,
|
||||
"plantuml": true
|
||||
},
|
||||
"home": {
|
||||
"index": "index.ejs",
|
||||
@@ -47,5 +48,8 @@
|
||||
"mathjax": {
|
||||
"output_format": "svg",
|
||||
"speak_text": true
|
||||
},
|
||||
"plantuml": {
|
||||
"output_format": "svg"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+27
-4
@@ -1,4 +1,5 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const showdown = require('showdown');
|
||||
|
||||
module.exports = (config) => {
|
||||
@@ -31,6 +32,25 @@ module.exports = (config) => {
|
||||
cb(data);
|
||||
};
|
||||
|
||||
if (config['modules']['plantuml']) {
|
||||
require('./script_loader')(path.join(__dirname, 'lib', 'plantuml_synchro.js'));
|
||||
}
|
||||
|
||||
const renderPlantUML = (data, cb) => {
|
||||
if (!config['modules']['plantuml'])
|
||||
return cb(data);
|
||||
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
||||
let match;
|
||||
while ((match = umlRegex.exec(data))) {
|
||||
const code = match[1].trim();
|
||||
const s = unescape(encodeURIComponent(code)); // jshint ignore:line
|
||||
const compressed = global['zip_deflate'](s);
|
||||
const url = `http://www.plantuml.com/plantuml/${config['plantuml']['output_format']}/${encode64(compressed)}`;// jshint ignore:line
|
||||
data = data.slice(0, match.index) + `<img alt="generated PlantUML diagram" src="${url}">` + data.slice(match.index + match[0].length);
|
||||
}
|
||||
cb(data);
|
||||
};
|
||||
|
||||
let mjAPI;
|
||||
if (config['modules']['mathjax']) {
|
||||
mjAPI = require('mathjax-node');
|
||||
@@ -81,16 +101,19 @@ module.exports = (config) => {
|
||||
return {
|
||||
renderShowDown: config['test'] ? renderShowDown : undefined,
|
||||
renderPrism: config['test'] ? renderPrism : undefined,
|
||||
renderPlantUML: config['test'] ? renderPlantUML : undefined,
|
||||
renderMathJax: config['test'] ? renderMathJax : undefined,
|
||||
render: (file, cb) => {
|
||||
fs.readFile(file, {encoding: 'UTF-8'}, (err, data) => {
|
||||
if (err)
|
||||
return cb(err);
|
||||
|
||||
renderPrism(data, (data2) => {
|
||||
renderMathJax(data2, (data3) => {
|
||||
renderShowDown(data3, (html) => {
|
||||
cb(null, html);
|
||||
renderPrism(data, (data) => {
|
||||
renderPlantUML(data, (data) => {
|
||||
renderMathJax(data, (data) => {
|
||||
renderShowDown(data, (html) => {
|
||||
cb(null, html);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Import client-side script into the "global" var
|
||||
* @param scriptPath
|
||||
*/
|
||||
module.exports = (scriptPath) => {
|
||||
eval.call(global, fs.readFileSync(scriptPath, {encoding: 'UTF-8'}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user