Skip to content

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
16ce3e1
katex [nfc]: Factor out MathNode from its block-vs-inline variants
gnprice Apr 21, 2025
3ac0037
katex [nfc]: Increment class index at top of loop
gnprice Apr 21, 2025
b003242
katex [nfc]: Join the CSS-class switch statements into one
gnprice Apr 21, 2025
b8186a7
katex [nfc]: Replace classFound local with a default case
gnprice Apr 22, 2025
9854bb8
katex [nfc]: Increment class index immediately on dereference
gnprice Apr 22, 2025
31e0bf0
katex [nfc]: Handle error immediately on spanClasses overrun
gnprice Apr 22, 2025
7751c0b
katex [nfc]: More early throws
gnprice Apr 22, 2025
403b157
katex [nfc]: Small further simplifications in CSS-class logic
gnprice Apr 22, 2025
d76120a
katex [nfc]: Make KatexSpanStyles immutable
gnprice Apr 22, 2025
31942c3
katex [nfc]: Compact a bit using switch-expressions
gnprice Apr 22, 2025
6bb726a
katex [nfc]: Factor out _KatexNodeList widget
gnprice Apr 22, 2025
0eb1410
katex [nfc]: Rename _KatexSpan field to "node"
gnprice Apr 22, 2025
d3b21fd
content test [nfc]: Use const for math block tests
rajveermalviya Apr 24, 2025
4b51709
content: Support parsing and handling inline styles for KaTeX content
rajveermalviya Apr 1, 2025
f794730
content: Scale inline KaTeX content based on the surrounding text
rajveermalviya Apr 22, 2025
5309a50
content [nfc]: Reintroduce KatexNode as a base sealed class
rajveermalviya Apr 24, 2025
a21ec64
content: Handle vertical offset spans in KaTeX content
rajveermalviya Apr 1, 2025
16cb28f
content: Support negative right-margin on KaTeX spans
rajveermalviya Apr 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 76 additions & 21 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ class CodeBlockSpanNode extends ContentNode {
}
}

class MathBlockNode extends BlockContentNode {
const MathBlockNode({
abstract class MathNode extends ContentNode {
const MathNode({
super.debugHtmlNode,
required this.texSource,
required this.nodes,
Expand All @@ -369,8 +369,12 @@ class MathBlockNode extends BlockContentNode {
}
}

class KatexNode extends ContentNode {
const KatexNode({
sealed class KatexNode extends ContentNode {
const KatexNode({super.debugHtmlNode});
}

class KatexSpanNode extends KatexNode {
Comment on lines +372 to +376
Copy link
Member

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.

const KatexSpanNode({
required this.styles,
required this.text,
required this.nodes,
Expand Down Expand Up @@ -402,6 +406,71 @@ class KatexNode extends ContentNode {
}
}

class KatexVlistNode extends KatexNode {
const KatexVlistNode({
required this.rows,
super.debugHtmlNode,
});

final List<KatexVlistRowNode> rows;

@override
List<DiagnosticsNode> debugDescribeChildren() {
return rows.map((row) => row.toDiagnosticsNode()).toList();
}
}

class KatexVlistRowNode extends ContentNode {
const KatexVlistRowNode({
required this.verticalOffsetEm,
this.nodes = const [],
});

final double verticalOffsetEm;
final List<KatexNode> nodes;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(StringProperty('verticalOffsetEm', '$verticalOffsetEm'));
}

@override
List<DiagnosticsNode> debugDescribeChildren() {
return nodes.map((node) => node.toDiagnosticsNode()).toList();
}
}

class KatexNegativeMarginNode extends KatexNode {
const KatexNegativeMarginNode({
required this.marginRightEm,
required this.nodes,
super.debugHtmlNode,
});

final double marginRightEm;
final List<KatexNode> nodes;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(StringProperty('marginRightEm', '$marginRightEm'));
}

@override
List<DiagnosticsNode> debugDescribeChildren() {
return nodes.map((node) => node.toDiagnosticsNode()).toList();
}
}

class MathBlockNode extends MathNode implements BlockContentNode {
const MathBlockNode({
super.debugHtmlNode,
required super.texSource,
required super.nodes,
});
}

class ImageNodeList extends BlockContentNode {
const ImageNodeList(this.images, {super.debugHtmlNode});

Expand Down Expand Up @@ -863,26 +932,12 @@ class ImageEmojiNode extends EmojiNode {
}
}

class MathInlineNode extends InlineContentNode {
class MathInlineNode extends MathNode implements InlineContentNode {
const MathInlineNode({
super.debugHtmlNode,
required this.texSource,
required this.nodes,
required super.texSource,
required super.nodes,
});

final String texSource;
final List<KatexNode>? nodes;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(StringProperty('texSource', texSource));
}

@override
List<DiagnosticsNode> debugDescribeChildren() {
return nodes?.map((node) => node.toDiagnosticsNode()).toList() ?? const [];
}
}

class GlobalTimeNode extends InlineContentNode {
Expand Down
Loading