Skip to content

Commit

Permalink
Merge pull request #21 from Klemek/dev
Browse files Browse the repository at this point in the history
v1.2.7
  • Loading branch information
Klemek authored Aug 19, 2019
2 parents 7d72e94 + add01b2 commit 4671253
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 113 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Any URL like `/year/month/day/anything/` will redirect to this article (and link
* **PlantUML**
It allows you to add UML diagrams with PlantUML Syntax between `@startuml` and `@enduml` (more info [here](http://www.plantuml.com))
* **fa-diagrams**
It allows you to define SVG diagrams with Font-Awesome icons in YAML between `@startfad` and `@endfad` (more info [here](https://github.com/Klemek/fa-diagrams))
It allows you to define SVG diagrams with Font-Awesome icons in [TOML](https://github.com/toml-lang/toml) between `@startfad` and `@endfad` (more info [here](https://github.com/Klemek/fa-diagrams))


## Configuration
Expand Down
104 changes: 25 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "gitblog.md",
"version": "1.2.6",
"version": "1.2.7",
"description": "A static blog using Markdown pulled from your git repository.",
"main": "src/server.js",
"dependencies": {
"@iarna/toml": "^2.2.3",
"body-parser": "^1.19.0",
"crypto": "^1.0.1",
"ejs": "^2.6.2",
"express": "^4.17.1",
"fa-diagrams": "^1.0.3",
"js-yaml": "^3.13.1",
"mathjax-node": "^2.1.1",
"ncp": "^2.0.0",
"node-prismjs": "^0.1.2",
Expand Down
44 changes: 24 additions & 20 deletions sample_data/article/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,30 @@ express -up-> web : 5. html
### Diagrams
[Back to top](#top)

You can use [fa-diagrams](https://github.com/Klemek/fa-diagrams) with `@startfad` and `@endfad` tags and using YAML inside

@startuml
nodes:
- name: node1
icon: laptop-code
color: '#4E342E'
bottom: my app
- name: node2
icon: globe
color: '#455A64'
bottom: world
links:
- from: node1
to: node2
color: '#333333'
top:
icon: envelope
bottom: '"hello"'
@enduml
You can use [fa-diagrams](https://github.com/Klemek/fa-diagrams) with `@startfad` and `@endfad` tags and using [TOML](https://github.com/toml-lang/toml) inside

@startfad
[[nodes]]
name = "node1"
icon = "laptop-code"
color = "#4E342E"
bottom = "my app"

[[nodes]]
name = "node2"
icon = "globe"
color = "#455A64"
bottom = "world"

[[links]]
from = "node1"
to = "node2"
color = "#333333"
bottom = '"hello"'

[links.top]
icon = "envelope"
@endfad

### Youtube Videos
[Back to top](#top)
Expand Down
6 changes: 3 additions & 3 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ module.exports = (config) => {
};

let faDiagrams;
let yaml;
let toml;
if (config['modules']['fa-diagrams']) {
faDiagrams = require('fa-diagrams');
yaml = require('js-yaml');
toml = require('@iarna/toml');
}

const renderFaDiagrams = (data, cb) => {
Expand All @@ -167,7 +167,7 @@ module.exports = (config) => {
const code = match[1].trim();
let output;
try {
const diagData = yaml.safeLoad(code);
const diagData = toml.parse(code);
const findLineBreaks = (data) => {
Object.keys(data).forEach(key => {
if (typeof data[key] === 'object')
Expand Down
19 changes: 11 additions & 8 deletions test/renderer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,29 @@ describe('Test MathJax', () => {
describe('Test fa-diagrams', () => {
test('no fa-diagrams', (done) => {
config['modules']['fa-diagrams'] = false;
renderer.renderFaDiagrams('@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad', (data) => {
expect(data).toBe('@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad');
renderer.renderFaDiagrams('@startfad\noptions.rendering.color=\'red\'\n@endfad', (data) => {
expect(data).toBe('@startfad\noptions.rendering.color=\'red\'\n@endfad');
done();
});
});
test('no fa-diagrams in code', (done) => {
renderer.renderFaDiagrams('code:\n```\n@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad\n```', (data) => {
expect(data).toBe('code:\n```\n@startfad\noptions:\n\trendering:\t\tcolor:red\n\n@endfad\n```');
renderer.renderFaDiagrams('code:\n```\n@startfad\noptions.rendering.color=\'red\'\n@endfad\n```', (data) => {
expect(data).toBe('code:\n```\n@startfad\noptions.rendering.color=\'red\'\n@endfad\n```');
done();
});
});
test('valid fa-diagrams', (done) => {
renderer.renderFaDiagrams('before\n@startfad\noptions:\n rendering:\n color: red\n@endfad\nafter', (data) => {
renderer.renderFaDiagrams('before\n@startfad\noptions.rendering.color=\'red\'\n@endfad\nafter', (data) => {
expect(data).toBe('before\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0" font-family="Arial" font-size="15" fill="red" stroke-width="0"></svg>\nafter');
done();
});
});
test('invalid yaml', (done) => {
renderer.renderFaDiagrams('before\n@startfad\noptions:\n@endfad\nafter', (data) => {
expect(data).toBe('before\n<b style="color:red">TypeError: Cannot convert undefined or null to object</b>\nafter');
test('invalid toml', (done) => {
renderer.renderFaDiagrams('before\n@startfad\noptions.rendering.color=red\n@endfad\nafter', (data) => {
expect(data).toBe('before\n<b style="color:red">TomlError: Unexpected character, expecting string, number, datetime, boolean, inline array or inline table at row 1, col 26, pos 25:\n' +
'1> options.rendering.color=red\n' +
' ^\n' +
'\n</b>\nafter');
done();
});
});
Expand Down

0 comments on commit 4671253

Please sign in to comment.