Skip to content

Commit

Permalink
Avoid extra mstyle attribute when setting mathvariant/mathcolor/mathb…
Browse files Browse the repository at this point in the history
…ackground on a single token element. #61
  • Loading branch information
fred-wang committed Apr 13, 2019
1 parent 764fff2 commit f6dc9af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
31 changes: 25 additions & 6 deletions TeXZilla.jison
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,36 @@ function newSpace(aWidth) {
return newTag("mspace", null, {"width": aWidth + "em"});
}
function isToken(aTree) {
return ["mi", "mn", "mo", "mtext", "ms"].indexOf(aTree.tag) !== -1;
}
function areTokenAttributes(aAttributes) {
for (var attribute in aAttributes) {
if (["mathcolor", "mathbackground", "mathvariant"].indexOf(attribute) === -1)
return false;
}
return true;
}
/* FIXME: try to restore the operator grouping when compoundTermList does not
contain any fences.
https://github.com/fred-wang/TeXZilla/issues/9 */
function newMrow(aList, aTag, aAttributes) {
var tag;
if (!aTag) {
if (aList.length == 1) {
/* This list only has one element so we just return it. */
return aList[0];
aTag = aTag || "mrow";
if (aList.length == 1) {
var child = aList[0];
if (aTag === "mrow")
return child;
if (aTag === "mstyle" &&
isToken(child) && areTokenAttributes(aAttributes)) {
child.attributes = {};
for (var name in aAttributes) {
if (!child.attributes[name])
child.attributes[name] = aAttributes[name];
}
return child;
}
aTag = "mrow";
}
return newTag(aTag, aList, aAttributes);
}
Expand Down
4 changes: 2 additions & 2 deletions unit-tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6dc9af

Please sign in to comment.