www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 99a81aca50e211bc3a616c618e16a0990f258f48
parent 379b98880d4f3ddb5c9754f5a672258c6399ebf2
Author: Emily Eisenberg <emily@khanacademy.org>
Date:   Wed,  1 Apr 2015 15:29:04 -0700

Fix the greediness of the `\color` function

Summary:
The greediness of the `\color` function wasn't set correctly,
leading to expressions like `\color{red}\text{a}` parsing correctly,
when they shouldn't. (This is based on how MathJax parses, since TeX
doesn't have a `\color` function, so MathJax is the standard).

Test Plan:
 - Make test
 - See that `\color{red}\text{a}` doesn't parse (like MathJax)
 - See that `\color{red}{\text{a}}` does parse (like MathJax)
 - See that `\color{red}\frac12` doesn't parse (like MathJax)
 - See that `\color{red}{\frac12}` does parse (like MathJax)
 - See that `\red\text{a}` doesn't parse (like MathJax)
 - See that `\red{\text{a}}` does parse (like MathJax)
 - See that `\red\frac12` doesn't parse (like MathJax)
 - See that `\red{\frac12}` does parse (like MathJax)

Reviewers: alpert

Reviewed By: alpert

Differential Revision: https://phabricator.khanacademy.org/D17130

Diffstat:
Msrc/functions.js | 2++
Mtest/katex-spec.js | 7+++++++
2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/functions.js b/src/functions.js @@ -112,6 +112,7 @@ var functions = { "\\color": { numArgs: 2, allowedInText: true, + greediness: 3, argTypes: ["color", "original"], handler: function(func, color, body) { // Normalize the different kinds of bodies (see \text above) @@ -235,6 +236,7 @@ var duplicatedFunctions = [ data: { numArgs: 1, allowedInText: true, + greediness: 3, handler: function(func, body) { var atoms; if (body.type === "ordgroup") { diff --git a/test/katex-spec.js b/test/katex-spec.js @@ -676,6 +676,13 @@ describe("A color parser", function() { it("should not parse a bad custom color", function() { expect(badCustomColorExpression).toNotParse(); }); + + it("should have correct greediness", function() { + expect("\\color{red}a").toParse(); + expect("\\color{red}{\\text{a}}").toParse(); + expect("\\color{red}\\text{a}").toNotParse(); + expect("\\color{red}\\frac12").toNotParse(); + }); }); describe("A tie parser", function() {