Skip to content

Split out KaTeX tests; simplify a bit; split KaTeX widgets from other content widgets #1729

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 11 commits into from
Jul 22, 2025

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Jul 22, 2025

This is the next round, after #1722, of the refactors I'd been contemplating for the KaTeX code but hadn't wanted to do before the logic we'd had in recent releases was merged. In this branch:

  • Split model/content_test.dart to match the implementation code; make a KatexExample subclass of ContentExample, with conveniences for KaTeX examples specifically.
  • Move KaTeX widgets to a new widgets/katex.dart, from widgets/content.dart. (Move their tests to a new file correspondingly.)
  • Simplify writing test data in a few different ways.
  • Add a bit of docs on each of the KaTeX-related content-node classes — particularly to help clarify the relationship between types like MathNode, KatexNode, and KatexSpanNode, which can sound similar on the face of things.

Selected commit messages

20eb9af katex test [nfc]: Split parsing tests to their own file, like implementation

This way we maintain our usual parallel between the files that tests
live in and the files with the code the tests are about.

There's more we can do to make use of having a specific class for
these. But we'll do that in separate commits, so that this massive
move commit is as pure of a move as possible.

286fede katex [nfc]: Move KaTeX widgets to their own file

This is a pretty self-contained swath of our content widgets -- the
only interface the others use from these is KatexWidget. So it works
well to split into a separate file, paralleling the model files.

3d5a4d8 katex test [nfc]: Make some examples more compact

f14e318 katex test [nfc]: Simplify a bit with a KatexExample.block constructor

This removes some repetitive noisy bits from these examples,
as well as a level of indentation.

1811266 katex test [nfc]: Use Dart raw strings to avoid double-backslash

This is available to us now that these strings don't include the
leading "math" and trailing "" lines, and the newlines
separating them from the main content.

afb3692 katex [nfc]: On KatexSpanNode constructor let text or nodes be omitted

We already have an assert enforcing that exactly one of these is
passed with a non-null (i.e. non-default) value. So there's no
risk of forgetting to specify a detail that should be specified.

af80c52 katex [nfc]: Let KatexSpanNode.styles default to empty

We have a lot of calls to the KatexSpanNode constructor in our tests,
and a large fraction of them pass an empty styles. Let that be the
default, reducing some noise. It's a natural default, since it
effectively means "do nothing".

a03c898 katex [nfc]: Add docs explaining the different content-node classes

@gnprice
Copy link
Member Author

gnprice commented Jul 22, 2025

@rajveermalviya the code moves in this PR will call for some conflict resolution in order to rebase your open KaTeX PRs atop this one. I'd like those PRs to also match the style changes here, even where Git doesn't flag a merge conflict.

The good news on that front is that I think this completes all the changes I had in mind that were likely to have merge conflicts with lots of other KaTeX work. 🙂 I still have other refactors in mind, but they affect narrower swaths of code and I think mostly won't call for any changes to existing open PRs.

Copy link
Member

@rajveermalviya rajveermalviya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for these refactors @gnprice! LGTM.

gnprice added 11 commits July 22, 2025 12:52
…ntation

This way we maintain our usual parallel between the files that tests
live in and the files with the code the tests are about.

There's more we can do to make use of having a specific class for
these.  But we'll do that in separate commits, so that this massive
move commit is as pure of a move as possible.
This will let us split some of this file's tests to a different file
and have them still use these helpers.
This is a pretty self-contained swath of our content widgets -- the
only interface the others use from these is KatexWidget.  So it works
well to split into a separate file, paralleling the model files.
This removes some repetitive noisy bits from these examples,
as well as a level of indentation.
This is available to us now that these strings don't include the
leading "```math" and trailing "```" lines, and the newlines
separating them from the main content.
We already have an assert enforcing that exactly one of these is
passed with a non-null (i.e. non-default) value.  So there's no
risk of forgetting to specify a detail that should be specified.
We have a lot of calls to the KatexSpanNode constructor in our tests,
and a large fraction of them pass an empty `styles`.  Let that be the
default, reducing some noise.  It's a natural default, since it
effectively means "do nothing".
@gnprice gnprice force-pushed the pr-katex-refactor branch from a03c898 to 5f85799 Compare July 22, 2025 19:53
@gnprice gnprice merged commit 5f85799 into zulip:main Jul 22, 2025
1 check passed
@gnprice gnprice deleted the pr-katex-refactor branch July 22, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants