Add a \color command for custom colors

Summary:
Keep track of the color inside the style now, and use that when we are
rendering things. Added a custom lexing mode to handle lexing colors correctly.
Prefixed the old katex colors (internally) with "katex-" to distinguish them
from CSS colors.

Test Plan:
 - Run the normal tests, see they work
 - Run the huxley tests, see that they didn't change except for the color one
   which looks right

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D7763
This commit is contained in:
Emily Eisenberg
2014-03-27 12:34:45 -04:00
parent 7723d3dcaf
commit d729ba5281
8 changed files with 159 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -11,7 +11,7 @@ url=http://localhost:7936/test/huxley/test.html?m=\dfrac{\frac{a}{b}}{\frac{c}{d
url=http://localhost:7936/test/huxley/test.html?m=a^{a^a_a}_{a^a_a}
[Colors]
url=http://localhost:7936/test/huxley/test.html?m=\blue{a}\green{b}\red{c}
url=http://localhost:7936/test/huxley/test.html?m=\blue{a}\color{%%230f0}{b}\color{red}{c}
[GreekLetters]
url=http://localhost:7936/test/huxley/test.html?m=\alpha\beta\gamma\omega

View File

@@ -496,3 +496,41 @@ describe("A text parser", function() {
expect(group[3].type).toMatch("spacing");
});
});
describe("A color parser", function() {
var colorExpression = "\\blue{x}";
var customColorExpression = "\\color{#fA6}{x}";
var badCustomColorExpression = "\\color{bad-color}{x}";
it("should not fail", function() {
expect(function() {
parseTree(colorExpression);
}).not.toThrow();
});
it("should build a color node", function() {
var parse = parseTree(colorExpression)[0];
expect(parse.type).toMatch("color");
expect(parse.value.color).toBeDefined();
expect(parse.value.value).toBeDefined();
});
it("should parse a custom color", function() {
expect(function() {
parseTree(customColorExpression);
}).not.toThrow();
});
it("should correctly extract the custom color", function() {
var parse = parseTree(customColorExpression)[0];
expect(parse.value.color).toMatch("#fA6");
});
it("should not parse a bad custom color", function() {
expect(function() {
parseTree(badCustomColorExpression);
}).toThrow();
});
});