gitbook-plugin-plantuml-renderer
Advanced tools
Comparing version 1.2.0 to 2.0.0
44
index.js
@@ -1,6 +0,4 @@ | ||
const plantumlEncoder = require('plantuml-encoder'); | ||
const http = require('http') | ||
const plantuml = require('node-plantuml'); | ||
const crypto = require('crypto'); | ||
const contentTypes = ['image/png', 'image/svg+xml'] | ||
module.exports = { | ||
@@ -13,30 +11,24 @@ blocks: { | ||
const encoded = plantumlEncoder.encode( | ||
block.body | ||
.replace(/\\\//g, `/`) | ||
.replace(/\\\[/g, `[`) | ||
.replace(/\\\]/g, `]`) | ||
.replace(/\\\(/g, `(`) | ||
.replace(/\\\)/g, `)`) | ||
.replace(/>/g, `>`) | ||
.replace(/</g, `<`) | ||
); | ||
const hash = encoded.slice(0, 16); | ||
const input = block.body | ||
.replace(/\\\//g, `/`) | ||
.replace(/\\\[/g, `[`) | ||
.replace(/\\\]/g, `]`) | ||
.replace(/\\\(/g, `(`) | ||
.replace(/\\\)/g, `)`) | ||
.replace(/>/g, `>`) | ||
.replace(/</g, `<`); | ||
const hash = crypto.createHash('md5').update(input).digest('hex'); | ||
const name = block.kwargs.name || hash; | ||
const path = `/plantuml/${hash}.${format}`; | ||
const href = `http://www.plantuml.com/plantuml/${format}/${encoded}`; | ||
return new Promise((resolve, reject) => { | ||
const request = http.get(href, (response) => { | ||
const body = []; | ||
response.on('data', (chunk) => body.push(chunk)); | ||
response.on('end', () => { | ||
if (!contentTypes.includes(response.headers['content-type'])) { | ||
reject(new Error(`Failed to load picture "${href}", response code: ${response.statusCode}`)); | ||
} | ||
plantuml.generate(input, {format: format}, (error, result) => { | ||
if (error) { | ||
reject(error); | ||
return | ||
} | ||
resolve(body.join('')) | ||
}); | ||
resolve(result); | ||
}); | ||
request.on('error', (err) => reject(err)); | ||
}).then(body => { | ||
@@ -43,0 +35,0 @@ return this.output.writeFile(path, body); |
@@ -8,5 +8,5 @@ { | ||
"dependencies": { | ||
"plantuml-encoder": "^1.2.5" | ||
"node-plantuml": "^0.7.0" | ||
}, | ||
"description": "UML Diagrams rendering using PlantUML.com", | ||
"description": "UML Diagrams rendering using PlantUML", | ||
"engines": { | ||
@@ -18,3 +18,3 @@ "gitbook": ">=2.0.0" | ||
"name": "gitbook-plugin-plantuml-renderer", | ||
"version": "1.2.0" | ||
"version": "2.0.0" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
16787
0
36
+ Addednode-plantuml@^0.7.0
+ Addedcommander@2.20.3(transitive)
+ Addednode-nailgun-client@0.1.2(transitive)
+ Addednode-nailgun-server@0.1.4(transitive)
+ Addednode-plantuml@0.7.0(transitive)
- Removedplantuml-encoder@^1.2.5