Improve JS spacing#1103
Conversation
Spacing around \href is handled in the `buildHTML`
+ Added getOutermostNode function
It is an array consisting type of nodes that will be added to the left and the right, and if given, will be used to determine bin cancellation and spacings of outermost nodes.
| // Build the inner expression | ||
| const inner = html.buildExpression(group.value.body, options, true); | ||
| const inner = html.buildExpression(group.value.body, options, true, | ||
| [null, "mclose"]); |
There was a problem hiding this comment.
This seems to be the on place where the surrounding param is used. Do you for other situations where we'll need the first value instead of just the second?
There was a problem hiding this comment.
@kevinbarabash Not yet, but I think it makes sense to have for both sides.
src/buildHTML.js
Outdated
| nonSpaces.unshift(surrounding[0] && | ||
| new makeSpan([surrounding[0]], [], options)); | ||
| nonSpaces.push(surrounding[1] && | ||
| new makeSpan([surrounding[1]], [], options)); |
There was a problem hiding this comment.
Is it necessary to create the spans if surrounding[0] or surrounding[1] is null or undefined?
There was a problem hiding this comment.
@kevinbarabash It's for easy manipulation of nonSpaces. This way, we can safely assume that nonSpaces[0] and nonSpaces[nonSpaces.length -1] are dummy spans.
There was a problem hiding this comment.
I would rewrite this as:
const nonSpaces = [
surrounding[0] && makeSpan([surrounding[0]], [], options)),
rawGroups.filter(group => group && group.classes[0] !== "mspace"),
surrounding[1] && makeSpan([surrounding[1]], [], options)),
];
This avoids the unshift which could be costly depending on the length of the array and better shows that the surrounding array is being used to surround something.
Note: new isn't required for makeSpan.
There was a problem hiding this comment.
I can't wait until we have everything converted to flow so that we can better enforce some of these assumptions.
| const dimension = | ||
| calculateSize(activeSpacings[lastChildType]["mclose"], options); | ||
| glue.style.marginRight = `${dimension}em`; | ||
| inner.push(glue); |
There was a problem hiding this comment.
Now this isn't included in inner/children. Won't that affect the results of getOutermostNode?
There was a problem hiding this comment.
@kevinbarabash The html.buildExpression inserts the appropriate spacing between the last child and mclose.
There was a problem hiding this comment.
That's pretty cool. Glad you were able to figure out a way to get all the spacing code in one place.
| } | ||
| } | ||
| return new buildCommon.makeAnchor(href, classes, elements, options); | ||
| return new buildCommon.makeAnchor(href, [], elements, options); |
| const right = getOutermostNode(nonSpaces[i], "right"); | ||
| if (right.classes[0] === "mbin" && | ||
| isBinRightCanceller(nonSpaces[i + 1], isRealGroup)) { | ||
| right.classes[0] = "mord"; |
|
@ylemkimon are you still planning to do the TODOs in the top comment? Did you want me to comment on the code as is before adding tests/updating screenshots? |
|
whoops... wrong PR |
|
@kevinbarabash Yes, and if you don’t mind, yes, please. Though, I’m not sure what is best way to add spacings recursively for \href and \class in #1074. |
src/buildHTML.js
Outdated
| */ | ||
| export const buildExpression = function(expression, options, isRealGroup) { | ||
| export const buildExpression = function(expression, options, isRealGroup, | ||
| surrounding = []) { |
There was a problem hiding this comment.
Maybe make this surrounding = [null, null]. I think eventually we'll want to enforce that this is a 2-tuple with flow.
k4b7
left a comment
There was a problem hiding this comment.
LGTM. I think the TODOs in the summary could be handled in a separate PR.
Codecov Report
@@ Coverage Diff @@
## master #1103 +/- ##
==========================================
+ Coverage 79.01% 79.37% +0.35%
==========================================
Files 59 59
Lines 3875 3865 -10
Branches 655 648 -7
==========================================
+ Hits 3062 3068 +6
+ Misses 672 662 -10
+ Partials 141 135 -6
Continue to review full report at Codecov.
|
k4b7
left a comment
There was a problem hiding this comment.
A couple of minor nits before merging:
- avoid
push/unshiftonnonSpaces - don't use
newonmakeSpan
|
I tried checking the checkboxes but apparently you can't do that to checkboxes inside review summaries. |
|
@ylemkimon thanks for the PR. |
\href: Spacing around\href(anchor) is handled in thehtml.buildExpression, and currently spacings around\hrefare duplicatedFix tight spacing not applied: Fix spacing code for "tight" styles #1102Fixed by use correct spacing with tight styles #1106delimsizing.jsfor its usage.TODO:
\href: Spacing inside \href is wrong #1108