-
Notifications
You must be signed in to change notification settings - Fork 306
KaTeX (2/n): Support horizontal and vertical offsets for spans #1452
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
base: main
Are you sure you want to change the base?
Conversation
d00e10f
to
7ff4f9e
Compare
7ff4f9e
to
c0dd0a1
Compare
This way there's nothing that needs to happen at the bottom of the loop, if any of the cases matched.
Conveniently, the two redundant rules say the exact same thing when they apply. So the first one has no effect, and we can ignore it.
Before this change, all cases of this switch statement either continue the loop, or throw, or set classFound to true. The error therefore gets logged just if none of the cases matched. So we can express the same behavior with a default case.
This makes the reasoning about these index values more local.
Like an early return, this (a) brings the consequence of the error immediately next to the condition defining it, and (b) lets the normal happy case continue vertically down without adding indentation.
Same motivation as in the parent commit.
Once the parsing is done, we want these to remain unchanged, just like the other objects in the parse tree. So, like ContentNode and its subclasses, make the class immutable. The parser needs to mutate its own draft of what styles to apply to a given span; but it can do that with its own local variables corresponding to the fields, and construct a styles object at the end of the loop.
This deduplicates the logic for the particular way that a list of KaTeX nodes get combined into a single widget.
This makes it more uniform with our other content widgets.
sealed class KatexNode extends ContentNode { | ||
const KatexNode({super.debugHtmlNode}); | ||
} | ||
|
||
class KatexSpanNode extends KatexNode { |
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.
One point that I noticed while developing #1478 (and checking how my draft of that branch interacted with this PR): it'd be good for this commit:
e268041 content: Handle vertical offset spans in KaTeX content
to get split up like so:
- First, an NFC prep commit introduces the distinction between KatexNode and KatexSpanNode. At this stage, the latter is the only subclass of the former.
- Then another commit makes the substantive changes this commit is about, including introducing the sibling subclasses KatexVlistNode and KatexVlistRowNode.
One reason that'd be useful is that the split between KatexNode and KatexSpanNode is somewhat nontrivial in itself: some of the references to KatexNode continue to say KatexNode, while others switch to saying KatexSpanNode, so the commit is expressing meaningful information by its choices of which references go which way.
This applies the correct font scaling if the KaTeX content is inside a header.
c0dd0a1
to
b17033a
Compare
And rename previous type to KatexSpanNode, also while making it a subtype of KatexNode.
Implement handling most common types of `vlist` spans.
Negative margin spans on web render to the offset being applied to the specific span and all the adjacent spans, so mimic the same behaviour here.
b17033a
to
16cb28f
Compare
Stacked on top of: #1408
Related: #46