-
Notifications
You must be signed in to change notification settings - Fork 433
/
index.js
35 lines (29 loc) · 839 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const pug = require('pug')
const fs = require('fs')
const path = require('path')
exports.constructor = async function (params) {
return {
watchers: [
{
extensions: ['.mermaid'],
handler: mermaidHandler
}
]
}
}
var mermaidHandler = async function (mermaidPath, page) {
var mermaidSpec = fs.readFileSync(mermaidPath, 'utf8')
var html = pug.renderFile(path.join(__dirname, 'template.pug'), {
mermaidSpec
})
await page.setContent(html)
await page.waitForSelector('#graph svg')
var svg = await page.evaluate(function () {
var el = document.querySelector('#graph svg')
el.removeAttribute('height')
el.classList.add('mermaid-svg')
return el.outerHTML
})
var svgPath = mermaidPath.substr(0, mermaidPath.lastIndexOf('.')) + '.svg'
fs.writeFileSync(svgPath, svg)
}