forked from kisonecat/dvi2html
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
51 lines (40 loc) · 1.37 KB
/
index.ts
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
import * as fs from "fs";
import { execSync } from "child_process";
import { dvi2html } from "./src";
import { Writable } from 'stream';
let fonts = "";
//fonts = fonts + `@font-face { font-family: esint10; src: url('./esint/esint10.ttf'); }\n`;
fs.readdirSync('./fonts').forEach(file => {
let name = file.replace(/.ttf/, '');
fonts = fonts + `@font-face { font-family: ${name}; src: url('fonts/${file}'); }\n`;
});
fs.writeFileSync("fonts.css", fonts);
//execSync("latex sample/sample.tex");
let filename = 'sample.dvi';
let stream = fs.createReadStream(filename, { highWaterMark: 256 });
var buffer = fs.readFileSync(filename);
let html = "";
html = html + "<!doctype html>\n";
html = html + "<html lang=en>\n";
html = html + "<head>\n";
html = html + '<link rel="stylesheet" type="text/css" href="fonts.css">\n';
html = html + '<link rel="stylesheet" type="text/css" href="base.css">\n';
html = html + "</head>\n";
html = html + '<body>\n';
html = html + '<div style="position: absolute; width: 100%;">\n';
//html = html + dviParser( buffer );
const myWritable = new Writable({
write(chunk, encoding, callback) {
html = html + chunk;
callback();
}
});
async function main() {
dvi2html( buffer, myWritable );
html = html + '</div>\n';
html = html + '</body>\n';
html = html + "</html>\n";
fs.writeFileSync("index.html", html);
}
main()
console.log("DONE");