mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-08 12:38:39 +00:00
Parse single superscripts and subscripts
Summary: Add the ability to parse lone `^x` and `_y`, etc. This basically just involves more checking of cases in the increasingly ugly `parseAtom` function. Also, now we manually check for the cases of double superscripts and subscripts. Test Plan: Make sure the tests pass. Make sure things like `^x` and `_y` parse. Reviewers: emily Reviewed By: emily Differential Revision: http://phabricator.khanacademy.org/D3095
This commit is contained in:
@@ -164,6 +164,24 @@ describe("A subscript and superscript parser", function() {
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("should not fail when there is no nucleus", function() {
|
||||
expect(function() {
|
||||
parseTree("^3");
|
||||
}).not.toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("_2");
|
||||
}).not.toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("^3_2");
|
||||
}).not.toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("_2^3");
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("should produce sups for superscript", function() {
|
||||
var parse = parseTree("x^2")[0];
|
||||
|
||||
@@ -207,16 +225,30 @@ describe("A subscript and superscript parser", function() {
|
||||
expect(parseA).toEqual(parseB);
|
||||
});
|
||||
|
||||
it("should not parse x^x^x", function() {
|
||||
it("should not parse double subscripts or superscripts", function() {
|
||||
expect(function() {
|
||||
parseTree("x^x^x");
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it("should not parse x_x_x", function() {
|
||||
expect(function() {
|
||||
parseTree("x_x_x");
|
||||
}).toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("x_x^x_x");
|
||||
}).toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("x_x^x^x");
|
||||
}).toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("x^x_x_x");
|
||||
}).toThrow();
|
||||
|
||||
expect(function() {
|
||||
parseTree("x^x_x^x");
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it("should work correctly with {}s", function() {
|
||||
|
Reference in New Issue
Block a user