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:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user