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:
Emily Eisenberg
2015-04-01 15:57:10 -07:00
parent 99a81aca50
commit cd9bca4a89
12 changed files with 595 additions and 35 deletions

View File

@@ -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);