commit a831e94a5114bfa231f6242dd862642a8959dda5
parent 0da85483c4c6f2cf775d0bdfaeed94a4e07a4bf3
Author: Emily Eisenberg <xymostech@gmail.com>
Date: Sat, 13 Jul 2013 20:42:19 -0700
Remove dependency on underscore
Summary:
Remove all uses of underscore. For the things we actually need, make a
"util" file and put them in there.
Test Plan:
Make sure the test still succeed, and that the main page still
works.
Reviewers: alpert
Reviewed By: alpert
Differential Revision: http://phabricator.khanacademy.org/D3043
Diffstat:
4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/Parser.js b/Parser.js
@@ -1,4 +1,5 @@
var Lexer = require("./Lexer");
+var utils = require("./utils");
// Main Parser class
function Parser() {
@@ -164,10 +165,6 @@ Parser.prototype.parseGroup = function(pos) {
}
};
-// Tests whether an element is in a list
-function contains(list, elem) {
- return list.indexOf(elem) !== -1;
-}
// A list of 1-argument color functions
var colorFuncs = [
@@ -211,7 +208,7 @@ for (var type in copyFuncs) {
Parser.prototype.parseNucleus = function(pos) {
var nucleus = this.lexer.lex(pos);
- if (contains(colorFuncs, nucleus.type)) {
+ if (utils.contains(colorFuncs, nucleus.type)) {
// If this is a color function, parse its argument and return
var group = this.parseGroup(nucleus.position);
if (group) {
diff --git a/katex.js b/katex.js
@@ -1,11 +1,16 @@
var parseTree = require("./parseTree");
+var utils = require("./utils");
+
var buildExpression = function(expression) {
- return _.map(expression, function(ex, i) {
+ var groups = [];
+ for (var i = 0; i < expression.length; i++) {
+ var group = expression[i];
var prev = i > 0 ? expression[i-1] : null;
- return buildGroup(ex, prev);
- });
+ groups.push(buildGroup(group, prev));
+ };
+ return groups;
};
var makeSpan = function(className, children) {
@@ -28,7 +33,7 @@ var buildGroup = function(group, prev) {
return makeSpan("mord", [textit(group.value)]);
} else if (group.type === "bin") {
var className = "mbin";
- if (prev == null || _.contains(["bin", "open", "rel"], prev.type)) {
+ if (prev == null || utils.contains(["bin", "open", "rel"], prev.type)) {
group.type = "ord";
className = "mord";
}
diff --git a/static/index.html b/static/index.html
@@ -2,7 +2,6 @@
<html>
<head>
<title>KaTeX Test</title>
- <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" type="text/javascript"></script>
<script src="katex.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
<link href="katex.css" rel="stylesheet" type="text/css">
diff --git a/utils.js b/utils.js
@@ -0,0 +1,7 @@
+function contains(list, elem) {
+ return list.indexOf(elem) !== -1;
+}
+
+module.exports = {
+ contains: contains
+}