From 90dfae69247f4357009a9317dda726636f44e96b Mon Sep 17 00:00:00 2001 From: Emily Eisenberg Date: Tue, 9 Jul 2013 22:31:19 -0700 Subject: [PATCH] Attempt to merge ords together Summary: Try not to waste spans by putting a bunch of numbers or letters together into the same ord box. I don't think that this breaks any of the current stuff. Test Plan: Write lots of expressions that have ords in them. Make sure that all the reasonable ords are grouped together, and that the formatting still works. Reviewers: spicyj Reviewed By: spicyj Differential Revision: http://phabricator.benalpert.com/D52 --- MJLite.js | 12 ++++-------- lexer.js | 3 ++- parser.jison | 6 ++++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/MJLite.js b/MJLite.js index 20c62de..07bd401 100644 --- a/MJLite.js +++ b/MJLite.js @@ -30,8 +30,10 @@ var makeSpan = function(className, children) { }; var buildGroup = function(group, prev) { - if (group.type === "ord") { + if (group.type === "mathord") { return makeSpan("mord", mathit(group.value)); + } else if (group.type === "textord") { + return makeSpan("mord", textit(group.value)); } else if (group.type === "bin") { var className = "mbin"; if (prev == null || _.contains(["bin", "open", "rel"], prev.type)) { @@ -123,13 +125,7 @@ var textit = function(value) { }; var mathit = function(value) { - var text = textit(value); - - if (/[a-zA-Z]/.test(value)) { - return makeSpan("mathit", text); - } else { - return text; - } + return makeSpan("mathit", textit(value)); }; var clearNode = function(node) { diff --git a/lexer.js b/lexer.js index d7d171e..69f4b1d 100644 --- a/lexer.js +++ b/lexer.js @@ -2,7 +2,8 @@ function Lexer() { }; var normals = [ - [/^[/|a-zA-Z0-9.]/, 'ORD'], + [/^[/|0-9.]+/, 'TEXTORD'], + [/^[a-zA-Z]+/, 'MATHORD'], [/^[*+-]/, 'BIN'], [/^[=<>]/, 'REL'], [/^[,;]/, 'PUNCT'], diff --git a/parser.jison b/parser.jison index aef67b1..fefcc2c 100644 --- a/parser.jison +++ b/parser.jison @@ -143,8 +143,10 @@ func ; atom - : 'ORD' - {$$ = [{type: 'ord', value: yytext}];} + : 'TEXTORD' + {$$ = [{type: 'textord', value: yytext}];} + | 'MATHORD' + {$$ = [{type: 'mathord', value: yytext}];} | 'BIN' {$$ = [{type: 'bin', value: yytext}];} | 'REL'