Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ea95a285c9 | |||
| 0fde428806 | |||
| 8fc7ff1ca7 | |||
| ae4e2eb8d5 | |||
| 528e4be1fe | |||
| bd42883330 | |||
| b6ac0a73b4 | |||
| aebc3da5bc | |||
| 7a4a4f9006 | |||
| 1341aa5a56 | |||
| 5e05f250f4 | |||
| 6cf7be3afb | |||
| 6aceacad18 | |||
| a3a23be1c2 | |||
| e8e8024021 | |||
| 1806d60ca7 | |||
| 2c5f2e589f | |||
| 847d228c0a | |||
| 576948acee | |||
| fa6d91db20 | |||
| 989bcdf130 | |||
| 000104c99d | |||
| f2bd0ec10e | |||
| 97dab302d8 | |||
| 55e258e093 | |||
| 7b22a4773d | |||
| 14cd1436c3 | |||
| c112e1ea62 | |||
| bd8385ea60 | |||
| 6dbc7f359b |
@@ -3,6 +3,7 @@
|
||||
/config.json
|
||||
/config.example.json
|
||||
/data
|
||||
/data/*
|
||||
/test_data
|
||||
/access.log
|
||||
/error.log
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/src/lib
|
||||
@@ -6,13 +6,8 @@ cache:
|
||||
npm: true
|
||||
directories:
|
||||
- node_modules
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- graphviz
|
||||
install:
|
||||
- npm install
|
||||
- npm install node-plantuml
|
||||
before_script:
|
||||
- npm install -g jshint
|
||||
script:
|
||||
|
||||
@@ -81,7 +81,7 @@ On the `/rss` endpoint, the servers gives you a RSS feed based on the list of ar
|
||||
#### 1. Download and install the latest version from the repo
|
||||
```bash
|
||||
git clone https://github.com/klemek/gitblog.md.git
|
||||
npm install
|
||||
npm install --production
|
||||
```
|
||||
#### 2. Create your config file
|
||||
```bash
|
||||
@@ -132,7 +132,10 @@ You need to [create a new repository](https://github.com/new) on your favorite G
|
||||
```bash
|
||||
#gitblog.md/
|
||||
cd data
|
||||
git init
|
||||
git remote add origin <url_of_your_repo.git>
|
||||
git add .
|
||||
git commit -m "initial commit"
|
||||
git push -u origin master
|
||||
```
|
||||
|
||||
@@ -157,7 +160,7 @@ Here are the steps for Github, if you use another platform adapt it your way (he
|
||||
```json
|
||||
"webhook": {
|
||||
"endpoint": "/webhook",
|
||||
"secret": "sha1=<value>",
|
||||
"secret": "<value>",
|
||||
"signature_header": "X-Hub-Signature"
|
||||
},
|
||||
```
|
||||
@@ -203,7 +206,9 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
|
||||
* **Prism**
|
||||
It highlight code blocks to be more readable (more info [here](https://prismjs.com/), you will need the corresponding CSS file on your templates)
|
||||
* **MathJax**
|
||||
It allows you to add math equations to your articles by simply writing LaTeX between $$ for full size (and between $ for inline) (more info [here](https://www.mathjax.org/))
|
||||
It allows you to add math equations to your articles by simply writing LaTeX between `$$` for full size (and between $ for inline) (more info [here](https://www.mathjax.org/))
|
||||
* **PlantUML**
|
||||
It allows you to add UML diagrams with PlantUML Syntax between `@startuml` and `@enduml` (more info [here](http://www.plantuml.com))
|
||||
|
||||
## Configuration
|
||||
[back to top](#gitblog-md)
|
||||
@@ -227,7 +232,15 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
|
||||
activate Prism code highlighting
|
||||
* `mathjax` (default: true)
|
||||
activate MathJax equations formatting
|
||||
* `plantuml` (default: true)
|
||||
activate PlantUML diagram rendering
|
||||
* `home`
|
||||
* `title` (default: GitBlog.md)
|
||||
the title of your blog, **strongly advised to be changed**
|
||||
given to the template to complete page title and metadata
|
||||
* `description` (default: A static blog using Markdown pulled from your git repository)
|
||||
the description of your blog, **strongly advised to be changed**
|
||||
given to the template to complete page title and metadata
|
||||
* `index` (default: index.ejs)
|
||||
the name of the home page template on the data directory
|
||||
it will receive `articles`, a list of articles for rendering
|
||||
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitblog.md",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitblog.md",
|
||||
"version": "1.0.3",
|
||||
"version": "1.2.0",
|
||||
"description": "A static blog using Markdown pulled from your git repository.",
|
||||
"main": "src/server.js",
|
||||
"dependencies": {
|
||||
@@ -43,7 +43,8 @@
|
||||
"src/**/*.js",
|
||||
"!/node_modules/",
|
||||
"!src/server.js",
|
||||
"!src/postinstall.js"
|
||||
"!src/postinstall.js",
|
||||
"!src/lib/*.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ If you see this page, that means it's working
|
||||
* [Check Boxes](#checkboxes)
|
||||
* [Spoilers](#spoilers)
|
||||
* [Math Equations](#mathequations)
|
||||
* [UML](#uml)
|
||||
* [Youtube Videos](#youtubevideos)
|
||||
|
||||
### Headers
|
||||
@@ -224,6 +225,33 @@ $$
|
||||
|
||||
Where $\alpha$ is cool
|
||||
|
||||
### UML
|
||||
[Back to top](#top)
|
||||
|
||||
You can use PlantUML diagrams with `@startuml` and `@enduml` tags :
|
||||
|
||||
@startuml
|
||||
title Article
|
||||
cloud web
|
||||
node nodejs {
|
||||
TCP -right- [express]
|
||||
[showdown]
|
||||
}
|
||||
package data {
|
||||
package "2019/06/18" {
|
||||
component index [
|
||||
index.md
|
||||
image.png
|
||||
...
|
||||
]
|
||||
}
|
||||
}
|
||||
web -down-> TCP : 1. /2019/06/18/title
|
||||
express -down-> index : 2. fetch
|
||||
index -up-> showdown : 3. markdown
|
||||
showdown -left-> express : 4. html
|
||||
express -up-> web : 5. html
|
||||
@enduml
|
||||
|
||||
### Youtube Videos
|
||||
[Back to top](#top)
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Error <%= error %></title>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<title><%= info.title %> - Error <%= error %></title>
|
||||
<%- include('head'); %>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<hr>
|
||||
<footer>
|
||||
<small><a href="/rss">RSS feed</a> - @<%= new Date().getFullYear() %> - Made with <a
|
||||
<small><a href="/rss">RSS feed</a> - <%= new Date().getFullYear() %> - Made with <a
|
||||
href="https://github.com/klemek/gitblog.md">GitBlog.md</a> (v<%= info.version %>)
|
||||
</small>
|
||||
</footer>
|
||||
</footer>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<% if(locals.article){ %>
|
||||
<%- `<meta property="og:title" content="${info.title} - ${article.title}">` %>
|
||||
<%- `<meta property="twitter:title" content="${info.title} - ${article.title}">` %>
|
||||
<%- `<meta property="og:description" content="${info.description}">` %>
|
||||
<%- `<meta property="twitter:description" content="${info.description}">` %>
|
||||
<%- `<meta property="org:url" content="${info.host + article.url}">` %>
|
||||
<% if (article.thumbnail) { %>
|
||||
<%- `<meta property="og:image" content="${info.host}/${article.thumbnail}">` %>
|
||||
<%- `<meta property="twitter:image" content="${info.host}/${article.thumbnail}">` %>
|
||||
<% } %>
|
||||
<link rel="stylesheet" type="text/css" href="/prism.css">
|
||||
<% } else { %>
|
||||
<%- `<meta property="og:title" content="${info.title} - Home">` %>
|
||||
<%- `<meta property="twitter:title" content="${info.title} - Home">` %>
|
||||
<%- `<meta property="og:description" content="${info.description}">` %>
|
||||
<%- `<meta property="twitter:description" content="${info.description}">` %>
|
||||
<%- `<meta property="org:url" content="${info.host}/">` %>
|
||||
<% } %>
|
||||
|
||||
<link rel="alternate" type="application/rss+xml" title="RSS feed" href="/rss"/>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
@@ -2,13 +2,13 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>GitBlog.md - Home</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<title><%= info.title %> - Home</title>
|
||||
<%- include('head'); %>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>GitBlog.md</h1>
|
||||
A static blog using Markdown pulled from your git repository
|
||||
<h1><%= info.title %></h1>
|
||||
<%= info.description %>
|
||||
<h2>Articles in this blog :</h2>
|
||||
<% articles.forEach((article) => { %>
|
||||
<div class="article">
|
||||
|
||||
@@ -8,7 +8,7 @@ body, html {
|
||||
}
|
||||
|
||||
body {
|
||||
font: 14px/1.45 -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif;
|
||||
font: 15px sans-serif;
|
||||
color: #111;
|
||||
-webkit-text-size-adjust: none;
|
||||
background-color: #F5F5F5;
|
||||
@@ -16,8 +16,8 @@ body {
|
||||
}
|
||||
|
||||
main {
|
||||
max-width: 75ch;
|
||||
padding: 2ch;
|
||||
max-width: 42rem;
|
||||
padding: 2rem;
|
||||
margin: auto;
|
||||
background-color: #F0F0F0;
|
||||
min-height: 100vh;
|
||||
@@ -58,7 +58,7 @@ blockquote {
|
||||
border-left: 0.5em solid #ccc;
|
||||
padding-left: 1em;
|
||||
margin: 0.25em 0;
|
||||
color: #333;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
blockquote > p {
|
||||
@@ -108,7 +108,7 @@ main.article div.header a.link-home {
|
||||
line-height: 2.4;
|
||||
}
|
||||
|
||||
main.article div.header h1, main.article div.header h2, div.article h3 {
|
||||
main.article div.header h1, main.article div.header h2 {
|
||||
margin-top: 0.85em;
|
||||
margin-bottom: 0.25em;
|
||||
font-size: 2em;
|
||||
@@ -123,11 +123,19 @@ main.article div.header span.time, div.article span.time {
|
||||
}
|
||||
|
||||
div.article {
|
||||
margin-left: 1em;
|
||||
margin: 0 1em 1em 1em;
|
||||
}
|
||||
|
||||
div.article h3 {
|
||||
font-size: 1.3em;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
div.article img{
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin-right:1em;
|
||||
margin-top:0.25em;
|
||||
}
|
||||
|
||||
#text {
|
||||
@@ -142,4 +150,4 @@ div.article h3 {
|
||||
#text img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>GitBlog.md - <%= article.title %></title>
|
||||
<link rel="stylesheet" type="text/css" href="/prism.css">
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<title><%= info.title %> - <%= article.title %></title>
|
||||
<%- include('head'); %>
|
||||
</head>
|
||||
<body>
|
||||
<main class="article">
|
||||
@@ -19,4 +18,4 @@
|
||||
<%- include('footer'); %>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
+14
-2
@@ -36,6 +36,7 @@ module.exports = (config) => {
|
||||
|
||||
const articles = {};
|
||||
let lastRSS = '';
|
||||
let host;
|
||||
|
||||
/**
|
||||
* Fetch articles from the data folder and send success as a response
|
||||
@@ -73,6 +74,9 @@ module.exports = (config) => {
|
||||
*/
|
||||
const render = (res, vPath, data, code = 200) => {
|
||||
data.info = {
|
||||
title: config['home']['title'],
|
||||
description: config['home']['description'],
|
||||
host: host,
|
||||
version: pjson.version
|
||||
};
|
||||
res.render(vPath, data, (err, html) => {
|
||||
@@ -100,6 +104,14 @@ module.exports = (config) => {
|
||||
});
|
||||
};
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (!host) {
|
||||
host = 'http://' + req.headers.host;
|
||||
console.log(cons.ok, 'Currently hosted on ' + host);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
//log request at result end
|
||||
app.use((req, res, next) => {
|
||||
if (config['access_log']) {
|
||||
@@ -148,7 +160,7 @@ module.exports = (config) => {
|
||||
});
|
||||
lastRSS = feed.xml();
|
||||
}
|
||||
res.type('rss').send(lastRSS);
|
||||
res.type(req.headers['user-agent'].match(/Mozilla/) ? 'text/xml' : 'rss').send(lastRSS);
|
||||
} else {
|
||||
showError(req.path, 404, res);
|
||||
}
|
||||
@@ -225,7 +237,7 @@ module.exports = (config) => {
|
||||
});
|
||||
|
||||
// serve all static files via get
|
||||
app.get('*', express.static(config['data_dir']));
|
||||
app.get('*', express.static(path.join(__dirname, '..', config['data_dir'])));
|
||||
// catch express.static errors (mostly not found) by displaying 404
|
||||
app.get('*', (req, res) => {
|
||||
showError(req.path, 404, res);
|
||||
|
||||
@@ -8,9 +8,12 @@
|
||||
"rss": true,
|
||||
"webhook": true,
|
||||
"prism": true,
|
||||
"mathjax": true
|
||||
"mathjax": true,
|
||||
"plantuml": true
|
||||
},
|
||||
"home": {
|
||||
"title": "GitBlog.md",
|
||||
"description": "A static blog using Markdown pulled from your git repository",
|
||||
"index": "index.ejs",
|
||||
"error": "error.ejs",
|
||||
"hidden": [
|
||||
@@ -34,7 +37,7 @@
|
||||
"endpoint": "/webhook",
|
||||
"secret": "",
|
||||
"signature_header": "",
|
||||
"pull_command": "git pull"
|
||||
"pull_command": "git pull origin master"
|
||||
},
|
||||
"showdown": {
|
||||
"parseImgDimensions": true,
|
||||
@@ -47,5 +50,8 @@
|
||||
"mathjax": {
|
||||
"output_format": "svg",
|
||||
"speak_text": true
|
||||
},
|
||||
"plantuml": {
|
||||
"output_format": "svg"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ const fs = require('fs');
|
||||
const merge = (ref, src) => {
|
||||
if (typeof ref !== typeof src) {
|
||||
return ref;
|
||||
} else if (ref.length && !src.length) {
|
||||
return ref;
|
||||
} else if (ref.length && src.length) {
|
||||
return src;
|
||||
} else if (typeof ref === 'object') {
|
||||
const out = {};
|
||||
Object.keys(ref).forEach((key) => out[key] = merge(ref[key], src[key]));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+29
-10
@@ -1,4 +1,5 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const showdown = require('showdown');
|
||||
|
||||
module.exports = (config) => {
|
||||
@@ -21,12 +22,27 @@ module.exports = (config) => {
|
||||
while ((match = codeRegex.exec(data))) {
|
||||
const lang = match[1].trim();
|
||||
const code = match[2].trim();
|
||||
try {
|
||||
const block = Prism.highlight(code, Prism.languages[lang] || Prism.languages.autoit, lang);
|
||||
data = data.slice(0, match.index) + `<pre><code class="${lang} language-${lang}">` + block + '</code></pre>' + data.slice(match.index + match[0].length);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
const block = Prism.highlight(code, Prism.languages[lang] || Prism.languages.autoit, lang);
|
||||
data = data.slice(0, match.index) + `<pre><code class="${lang} language-${lang}">` + block + '</code></pre>' + data.slice(match.index + match[0].length);
|
||||
}
|
||||
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);
|
||||
};
|
||||
@@ -81,16 +97,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'}));
|
||||
};
|
||||
|
||||
+11
-2
@@ -175,11 +175,19 @@ describe('Test RSS feed', () => {
|
||||
test('200 empty rss', (done) => {
|
||||
request(app).get('/rsstest').then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.type).toBe('application/rss+xml');
|
||||
expect(response.text.length).toBeGreaterThan(0);
|
||||
expect(response.text.split('<item>').length).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('200 Mozilla fix', (done) => {
|
||||
request(app).get('/rsstest').set('user-agent', 'Mozilla Firefox 64.0').then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.type).toBe('text/xml');
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('200 rss cache', (done) => {
|
||||
request(app).get('/rsstest').then(() => {
|
||||
request(app).get('/rsstest').then((response) => {
|
||||
@@ -385,9 +393,10 @@ describe('Test static files', () => {
|
||||
});
|
||||
});
|
||||
test('200 valid file', (done) => {
|
||||
fs.writeFileSync(path.join(dataDir, 'somefile.txt'), 'filecontent');
|
||||
request(app).get('/somefile.txt').then((response) => {
|
||||
fs.writeFileSync(path.join(dataDir, 'somefile.css'), 'filecontent');
|
||||
request(app).get('/somefile.css').then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.type).toBe('text/css');
|
||||
expect(response.text).toBe('filecontent');
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -64,4 +64,18 @@ test('wrong config fixed', () => {
|
||||
expect(config).toBeDefined();
|
||||
expect(config['node_port']).toBe(3000);
|
||||
expect(config['data_dir']).toBe('data2');
|
||||
});
|
||||
|
||||
test('array parsing', () => {
|
||||
fs.writeFileSync(configFile, '{"home":{"hidden":["item1","item2"]}}');
|
||||
const config = require('../src/config')();
|
||||
expect(config).toBeDefined();
|
||||
expect(config['home']['hidden']).toEqual(['item1', 'item2']);
|
||||
});
|
||||
|
||||
test('array fix', () => {
|
||||
fs.writeFileSync(configFile, '{"home":{"hidden":{}}}');
|
||||
const config = require('../src/config')();
|
||||
expect(config).toBeDefined();
|
||||
expect(config['home']['hidden']).toEqual(['.ejs']);
|
||||
});
|
||||
+31
-1
@@ -10,7 +10,8 @@ const config = {
|
||||
'test': true,
|
||||
'modules': {
|
||||
'prism': true,
|
||||
'mathjax': true
|
||||
'mathjax': true,
|
||||
'plantuml': true
|
||||
},
|
||||
'showdown': {
|
||||
'simplifiedAutoLink': true,
|
||||
@@ -19,6 +20,9 @@ const config = {
|
||||
'mathjax': {
|
||||
'output_format': 'html',
|
||||
'speak_text': false
|
||||
},
|
||||
'plantuml': {
|
||||
'output_format': 'svg'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,6 +31,7 @@ const renderer = require('../src/renderer')(config);
|
||||
beforeEach(() => {
|
||||
config['modules']['prism'] = true;
|
||||
config['modules']['mathjax'] = true;
|
||||
config['modules']['plantuml'] = true;
|
||||
utils.deleteFolderSync(dataDir);
|
||||
fs.mkdirSync(dataDir);
|
||||
});
|
||||
@@ -91,6 +96,31 @@ describe('Test Prism', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test PlantUML', () => {
|
||||
test('no plantuml', (done) => {
|
||||
config['modules']['plantuml'] = false;
|
||||
renderer.renderPlantUML('@startuml\nBob -> Alice : hello\n@enduml', (data) => {
|
||||
expect(data).toBe('@startuml\nBob -> Alice : hello\n@enduml');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('plantuml correct', (done) => {
|
||||
renderer.renderPlantUML('@startuml\nBob -> Alice : hello\n@enduml', (data) => {
|
||||
expect(data).toBe('<img alt="generated PlantUML diagram" src="http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000">');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('plantuml multiple uml', (done) => {
|
||||
renderer.renderPlantUML('@startuml\nBob -> Alice : hello\n@enduml\n@startuml\nBob -> Alice : hello\n@enduml', (data) => {
|
||||
expect(data).toBe('<img alt="generated PlantUML diagram" src="http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000">\n<img alt="generated PlantUML diagram" src="http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000">');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Test MathJax', () => {
|
||||
test('no mathjax', (done) => {
|
||||
config['modules']['mathjax'] = false;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/* jshint -W117 */
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./test_utils');
|
||||
|
||||
const dataDir = 'test_data';
|
||||
|
||||
beforeEach(() => {
|
||||
utils.deleteFolderSync(dataDir);
|
||||
fs.mkdirSync(dataDir);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
if (fs.existsSync(dataDir)) {
|
||||
utils.deleteFolderSync(dataDir);
|
||||
}
|
||||
});
|
||||
|
||||
test('load 1 script', () => {
|
||||
const file = path.join(dataDir, 'test.js');
|
||||
fs.writeFileSync(file, `
|
||||
var a = 5;
|
||||
function b(){
|
||||
return a;
|
||||
}`);
|
||||
require('../src/script_loader')(file);
|
||||
expect(global['b']).toBeDefined();
|
||||
expect(global['b']()).toBe(5);
|
||||
});
|
||||
|
||||
test('load 2 script', () => {
|
||||
const file1 = path.join(dataDir, 'test.js');
|
||||
fs.writeFileSync(file1, `
|
||||
var a = 5;
|
||||
function b(){
|
||||
return a;
|
||||
}`);
|
||||
const file2 = path.join(dataDir, 'test2.js');
|
||||
fs.writeFileSync(file2, `
|
||||
var a = 9;
|
||||
function b(){
|
||||
return a;
|
||||
}`);
|
||||
require('../src/script_loader')(file1);
|
||||
expect(global['b']).toBeDefined();
|
||||
expect(global['b']()).toBe(5);
|
||||
|
||||
require('../src/script_loader.js')(file2);
|
||||
expect(global['b']).toBeDefined();
|
||||
expect(global['b']()).toBe(9);
|
||||
});
|
||||
Reference in New Issue
Block a user