Skip to content

Commit d4ccfc8

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 2e0c092 commit d4ccfc8

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
@@ -313,10 +313,7 @@ class _KatexParser {
313313
}
314314
final pstrutHeight = pstrutStyles.heightEm ?? 0;
315315

316-
KatexSpanNode innerSpanNode = KatexSpanNode(
317-
styles: styles,
318-
text: null,
319-
nodes: _parseChildSpans(otherSpans));
316+
final KatexSpanNode innerSpanNode;
320317

321318
final marginRightEm = styles.marginRightEm;
322319
final marginLeftEm = styles.marginLeftEm;
@@ -327,11 +324,17 @@ class _KatexParser {
327324
innerSpanNode = KatexSpanNode(
328325
styles: KatexSpanStyles(),
329326
text: null,
330-
nodes: [
331-
KatexNegativeMarginNode(
332-
leftOffsetEm: marginLeftEm,
333-
nodes: [innerSpanNode]),
334-
]);
327+
nodes: [KatexNegativeMarginNode(
328+
leftOffsetEm: marginLeftEm,
329+
nodes: [KatexSpanNode(
330+
styles: styles.filter(topEm: false, marginLeftEm: false),
331+
text: null,
332+
nodes: _parseChildSpans(otherSpans))])]);
333+
} else {
334+
innerSpanNode = KatexSpanNode(
335+
styles: styles.filter(topEm: false),
336+
text: null,
337+
nodes: _parseChildSpans(otherSpans));
335338
}
336339

337340
rows.add(KatexVlistRowNode(

test/model/content_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,10 +2575,7 @@ void main() async {
25752575
testParseExample(ContentExample.mathBlockKatexSubSuperScript);
25762576
testParseExample(ContentExample.mathBlockKatexRaisebox);
25772577
testParseExample(ContentExample.mathBlockKatexNegativeMargins);
2578-
testParseExample(ContentExample.mathBlockNegativeMarginsOnVlistRow,
2579-
// TODO fix parser to filter negative margins styles from
2580-
// vlist row span styles.
2581-
skip: true);
2578+
testParseExample(ContentExample.mathBlockNegativeMarginsOnVlistRow);
25822579

25832580
testParseExample(ContentExample.imageSingle);
25842581
testParseExample(ContentExample.imageSingleNoDimensions);

0 commit comments

Comments
 (0)