Skip to content

KaTeX (3/n): Support negative margins for spans #1559

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 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
8597804
content test [nfc]: Use const for math block tests
rajveermalviya Apr 24, 2025
4d3660d
content test [nfc]: Enable skips in testParseExample and testParse
gnprice May 29, 2025
6da2d63
content [nfc]: Inline _logError in _KatexParser._parseSpan
rajveermalviya May 8, 2025
4312dc6
content [nfc]: Refactor _KatexParser._parseChildSpans to take list of…
rajveermalviya May 8, 2025
e8bbfa3
content: Scale inline KaTeX content based on the surrounding text
rajveermalviya Apr 22, 2025
5513a2b
content: Populate `debugHtmlNode` for KatexNode
rajveermalviya May 27, 2025
d73e11c
content: Support parsing and handling inline styles for KaTeX content
rajveermalviya Apr 1, 2025
7bf54a7
content [nfc]: Reintroduce KatexNode as a base sealed class
rajveermalviya Apr 24, 2025
ab86277
content: Handle 'strut' span in KaTeX content
rajveermalviya May 29, 2025
fde2cfd
content: Ignore more KaTeX classes that don't have CSS definition
rajveermalviya May 19, 2025
7f1fca3
content: Handle 'mspace' and 'msupsub' KaTeX CSS classes
rajveermalviya May 19, 2025
b7e998f
content: Handle positive margin-right and margin-left in KaTeX spans
rajveermalviya May 19, 2025
4a11162
content: Handle 'top' property in KaTeX span inline style
rajveermalviya May 19, 2025
d2c63a1
content [nfc]: Remove the `inline` property in _Katex widget
rajveermalviya May 19, 2025
0a66a8d
content: Handle vertical offset spans in KaTeX content
rajveermalviya Apr 1, 2025
d1f5d5c
content: Support negative margins 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
79 changes: 77 additions & 2 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ abstract class MathNode extends ContentNode {
}
}

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

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

class KatexStrutNode extends KatexNode {
const KatexStrutNode({
required this.heightEm,
required this.verticalAlignEm,
super.debugHtmlNode,
});

final double heightEm;
final double? verticalAlignEm;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DoubleProperty('heightEm', heightEm));
properties.add(DoubleProperty('verticalAlignEm', verticalAlignEm));
}
}

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,
required this.node,
super.debugHtmlNode,
});

final double verticalOffsetEm;
final KatexSpanNode node;

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

class KatexNegativeMarginNode extends KatexNode {
const KatexNegativeMarginNode({
required this.leftOffsetEm,
required this.nodes,
super.debugHtmlNode,
}) : assert(leftOffsetEm < 0);

final double leftOffsetEm;
final List<KatexNode> nodes;

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

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

class MathBlockNode extends MathNode implements BlockContentNode {
const MathBlockNode({
super.debugHtmlNode,
Expand Down
Loading