1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-24 09:13:07 +02:00

no more client-side mathjax

This commit is contained in:
Pomax
2015-12-31 16:08:16 -08:00
parent 83ba8e1bf4
commit d9a0bac687
36 changed files with 3567 additions and 1488 deletions

View File

@@ -1,3 +1,8 @@
var sha1 = require("sha1");
var fs = require("fs");
var execSync = require("child_process").execSync;
var op = "\\[";
var ed = "\\]";
@@ -25,8 +30,22 @@ function escapeBlockLaTeX(source) {
throw new Error("improperly closed LaTeX encountered!");
}
latex = source.substring(curr, term + ed.length);
latex = latex.replace(/([{}])/g,"{'$1'}");
newsource += latex;
// convert this LaTeX code into an SVG file in ./images/latex,
// using mathjax-node in the ./tools directory
var hash = sha1(latex);
var filename = "images/latex/" + hash + ".svg";
var destination = __dirname + "/../" + filename;
var rewrite = '<img className="LaTeX SVG" src="/' + filename + '"/>';
// And only generate if the file doesn't already exist, of course.
if (!fs.existsSync(destination)) {
var cmdarg = new Buffer(latex).toString("base64");
var cmd = "npm run latex -- --hash " + hash + " --base64 " + cmdarg;
execSync(cmd);
}
newsource += rewrite;
}
return newsource + source.substring(from);
}