Skip to content

Commit 0ec2cc5

Browse files
content: Filter negative margin styles if present on a vlist row
This fixes a bug where if negative margin on a vlist row is present the widget side code would hit an assert. Displaying the error (red screen) in debug mode, but in release mode the negative padding would be applied twice, once by `_KatexNegativeMargin` and another by `Padding` widget.
1 parent f845c6d commit 0ec2cc5

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/model/katex.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ class _KatexParser {
332332
}
333333
final pstrutHeight = pstrutStyles.heightEm ?? 0;
334334

335-
KatexSpanNode innerSpanNode = KatexSpanNode(
336-
styles: styles,
337-
text: null,
338-
nodes: _parseChildSpans(otherSpans));
335+
final KatexSpanNode innerSpanNode;
339336

340337
final marginRightEm = styles.marginRightEm;
341338
final marginLeftEm = styles.marginLeftEm;
@@ -346,11 +343,17 @@ class _KatexParser {
346343
innerSpanNode = KatexSpanNode(
347344
styles: KatexSpanStyles(),
348345
text: null,
349-
nodes: [
350-
KatexNegativeMarginNode(
351-
leftOffsetEm: marginLeftEm,
352-
nodes: [innerSpanNode]),
353-
]);
346+
nodes: [KatexNegativeMarginNode(
347+
leftOffsetEm: marginLeftEm,
348+
nodes: [KatexSpanNode(
349+
styles: styles.filter(topEm: false, marginLeftEm: false),
350+
text: null,
351+
nodes: _parseChildSpans(otherSpans))])]);
352+
} else {
353+
innerSpanNode = KatexSpanNode(
354+
styles: styles.filter(topEm: false),
355+
text: null,
356+
nodes: _parseChildSpans(otherSpans));
354357
}
355358

356359
rows.add(KatexVlistRowNode(

test/model/content_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,10 +2457,7 @@ void main() async {
24572457
testParseExample(ContentExample.mathBlockKatexRaisebox);
24582458
testParseExample(ContentExample.mathBlockKatexNegativeMargin);
24592459
testParseExample(ContentExample.mathBlockKatexLogo);
2460-
testParseExample(ContentExample.mathBlockNegativeMarginsOnVlistRow,
2461-
// TODO fix parser to filter negative margins styles from
2462-
// vlist row span styles.
2463-
skip: true);
2460+
testParseExample(ContentExample.mathBlockNegativeMarginsOnVlistRow);
24642461

24652462
testParseExample(ContentExample.imageSingle);
24662463
testParseExample(ContentExample.imageSingleNoDimensions);

0 commit comments

Comments
 (0)