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
b42f784
content test [nfc]: Use const for math block tests
rajveermalviya Apr 24, 2025
4231608
content test [nfc]: Enable skips in testParseExample and testParse
gnprice May 29, 2025
04a3d25
content [nfc]: Inline _logError in _KatexParser._parseSpan
rajveermalviya May 8, 2025
e2022de
content [nfc]: Refactor _KatexParser._parseChildSpans to take list of…
rajveermalviya May 8, 2025
82c6b01
content: Populate `debugHtmlNode` for KatexNode
rajveermalviya May 27, 2025
b6da144
content [nfc]: Reintroduce KatexNode as a base sealed class
rajveermalviya Apr 24, 2025
c8f7d0b
content: Ignore more KaTeX classes that don't have CSS definition
rajveermalviya May 19, 2025
51fb5f5
content: Handle 'mspace' and 'msupsub' KaTeX CSS classes
rajveermalviya May 19, 2025
db0c1d8
content [nfc]: Remove the `inline` property in _Katex widget
rajveermalviya May 19, 2025
0bf40b8
content: Support parsing and handling inline styles for KaTeX content
rajveermalviya Apr 1, 2025
0434863
content: Scale inline KaTeX content based on the surrounding text
rajveermalviya Apr 22, 2025
d81008f
content: Handle 'strut' span in KaTeX content
rajveermalviya May 29, 2025
532b324
content: Handle positive margin-right and margin-left in KaTeX spans
rajveermalviya May 19, 2025
fef8a60
content: Handle 'top' property in KaTeX span inline style
rajveermalviya May 19, 2025
2c5a28c
content: Handle vertical offset spans in KaTeX content
rajveermalviya Apr 1, 2025
bf886a6
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