-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve getNode() so that is finds the correct node. #1447 #1459
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Much easier to understand. No idea what the original was doing... But what if there are multiple children without id?
Another problem I can see is that you now accumulate stack space. It's not tail recursive and in JS < ES6 it would not help anyway. Also would a query selector not be a better alternative (assuming there is no IE8 problem)?
One way to make it a bit more lightweight is to bind the name test outside the recursive context.
Uh oh!
There was an error while loading. Please reload this page.
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.
All good observations, especially for a general search command.
This is not a general search command, however. It is used (in several places) for one specific purpose: when an embellished operator needs to have its operator to be stretched, the embellishments may need to be adjusted. For example, an
munderoverwith a base that is stretched may need to have its over accent stretched as well. In these cases, the parent element (munderoverin this example) needs to locate the elements that it has used for the base and over nodes. This routine allows the parent to locate those elements. These elements have class names that are things likemjx-baseandmjx-over, and those elements are containers in which the actual child MathML nodes are rendered. Usually, they are the direct children of the element used for themunderover, but in some cases, there is an intervening element.All the nodes that correspond to the original MathML elements are given ids, but the
mjx-baseand other such sub-parts of themunderoverdo not. So the test looks through the direct children of the given element for one with the correct type, but if the child has no id (there will be only one in that case), we look for its children instead.In practice, the routine will only recurse once (at most), so I'm not too worked about tail recursion or the extra
RegExpcall here. But I suppose it could be done more directly aswhich avoids the recursion all together.
Uh oh!
There was an error while loading. Please reload this page.
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.
PS, I originally did use a query selector, but the problem is we want to get only the nodes that correspond to the direct children of the given node. In the case of something like
msubsup(whose code is shared withmsubandmsup), when there is nomjx-supelement, we want to returnnull. But a query selection might find anmjx-supin an element further down (in the subscript or the base). We want to avoid that. Note that this version of the routine avoids walking into any child node that has anid. Every element that comes from a MathML element will have anid, so we never walk into other MathML nodes. That means we only check the structural elements that are part of the output for the parent node, not the renderings of any of the children.Since the children could be arbitrarily complicated, query selector might have to look through lots of output. Here, we are going to look through three or four elements at most.