mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 19:28:39 +00:00
Add basic auto-render extension
Summary: Add an auto-render extension to render math on a page. It exposes a global function (maybe we should attach it to `katex`?) to render math in an element. It comes with a README on how to use it. Also, make `make build` build the minified file. Fixes #26 Test Plan: - Visit http://localhost:7936/contrib/auto-render/ - See that all of the math renders correctly - `make test` Reviewers: alpert, kevinb Reviewed By: kevinb Differential Revision: https://phabricator.khanacademy.org/D16620
This commit is contained in:
53
server.js
53
server.js
@@ -9,20 +9,33 @@ var app = express();
|
||||
|
||||
app.use(express.logger());
|
||||
|
||||
app.get("/katex.js", function(req, res, next) {
|
||||
var b = browserify();
|
||||
b.add("./katex");
|
||||
var serveBrowserified = function(file, standaloneName) {
|
||||
return function(req, res, next) {
|
||||
var b = browserify();
|
||||
b.add(file);
|
||||
|
||||
var stream = b.bundle({standalone: "katex"});
|
||||
var options = {};
|
||||
if (standaloneName) {
|
||||
options.standalone = standaloneName;
|
||||
}
|
||||
|
||||
var body = "";
|
||||
stream.on("data", function(s) { body += s; });
|
||||
stream.on("error", function(e) { next(e); });
|
||||
stream.on("end", function() {
|
||||
res.setHeader("Content-Type", "text/javascript");
|
||||
res.send(body);
|
||||
});
|
||||
});
|
||||
var stream = b.bundle(options);
|
||||
|
||||
var body = "";
|
||||
stream.on("data", function(s) { body += s; });
|
||||
stream.on("error", function(e) { next(e); });
|
||||
stream.on("end", function() {
|
||||
res.setHeader("Content-Type", "text/javascript");
|
||||
res.send(body);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
app.get("/katex.js", serveBrowserified("./katex", "katex"));
|
||||
app.get("/test/katex-spec.js", serveBrowserified("./test/katex-spec"));
|
||||
app.get("/contrib/auto-render/auto-render.js",
|
||||
serveBrowserified("./contrib/auto-render/auto-render",
|
||||
"renderMathInElement"));
|
||||
|
||||
app.get("/katex.css", function(req, res, next) {
|
||||
fs.readFile("static/katex.less", {encoding: "utf8"}, function(err, data) {
|
||||
@@ -48,24 +61,10 @@ app.get("/katex.css", function(req, res, next) {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/test/katex-spec.js", function(req, res, next) {
|
||||
var b = browserify();
|
||||
b.add("./test/katex-spec");
|
||||
|
||||
var stream = b.bundle({});
|
||||
|
||||
var body = "";
|
||||
stream.on("data", function(s) { body += s; });
|
||||
stream.on("error", function(e) { next(e); });
|
||||
stream.on("end", function() {
|
||||
res.setHeader("Content-Type", "text/javascript");
|
||||
res.send(body);
|
||||
});
|
||||
});
|
||||
|
||||
app.use(express.static(path.join(__dirname, "static")));
|
||||
app.use(express.static(path.join(__dirname, "build")));
|
||||
app.use("/test", express.static(path.join(__dirname, "test")));
|
||||
app.use("/contrib", express.static(path.join(__dirname, "contrib")));
|
||||
|
||||
app.use(function(err, req, res, next) {
|
||||
console.error(err.stack);
|
||||
|
Reference in New Issue
Block a user