This repository was archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
57 lines (50 loc) · 1.33 KB
/
build.js
File metadata and controls
57 lines (50 loc) · 1.33 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
let args = process.argv.slice(2)
if (args.length < 1 || args.length > 2)
process.exit(1)
const input = args[0]
const output = (args.length > 1) ? args[1] : input
const yaml = require('js-yaml')
const fs = require('fs')
const mjpage = require('mathjax-node-page').mjpage
mjpage(fs.readFileSync(input, 'utf8'), {
format: ['AsciiMath'],
output: 'svg',
cssInline: false,
MathJax: {
ascii2jax: {
delimiters: [['\\(', '\\)'], ['\\[', '\\]']],
},
},
displayMessages: true,
displayErrors: true,
}, {
linebreaks: true,
ex: 9, width: 60,
useGlobalCache: true,
}, (doc) => {
require('jsdom-global')(doc)
window.d3 = require('d3')
const functionPlot = require('function-plot')
const elements = document.querySelectorAll('.function-plot')
for (const target of elements) {
const text = target.textContent
target.innerHTML = ''
functionPlot({
target: target,
disableZoom: true,
...yaml.load(text),
})
const plot = target.firstChild
const [ width, height ] = [
plot.getAttribute('width'),
plot.getAttribute('height') - 2,
]
plot.removeAttribute('width')
plot.removeAttribute('height')
plot.setAttribute('viewBox', `0 0 ${width} ${height}`)
plot.remove()
target.parentNode.insertBefore(plot, target)
target.remove()
}
fs.writeFileSync(output, `<!doctype html>${document.documentElement.outerHTML}`, 'utf8')
})