-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve JS spacing #1103
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.
@@ -161,7 +159,8 @@ defineFunction({ | |||
}, | |||
htmlBuilder: (group, options) => { | |||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to create the spans if surrounding[0]
or surrounding[1]
is null
or undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this isn't included in inner
/children
. Won't that affect the results of getOutermostNode
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinbarabash The html.buildExpression
inserts the appropriate spacing between the last child and mclose
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
const right = getOutermostNode(nonSpaces[i], "right"); | ||
if (right.classes[0] === "mbin" && | ||
isBinRightCanceller(nonSpaces[i + 1], isRealGroup)) { | ||
right.classes[0] = "mord"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make this surrounding = [null, null]
. I think eventually we'll want to enforce that this is a 2-tuple with flow
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor nits before merging:
- avoid
push
/unshift
onnonSpaces
- don't use
new
onmakeSpan
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\href
are duplicatedFix tight spacing not applied: Fix spacing code for "tight" styles #1102Fixed by use correct spacing with tight styles #1106delimsizing.js
for its usage.TODO:
\href
: Spacing inside \href is wrong #1108