Skip to content

Commit 4ad7f83

Browse files
content test: Add test for negative margins on a vlist row in KaTeX content
1 parent 44da4e2 commit 4ad7f83

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

test/model/content_test.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,70 @@ class ContentExample {
12801280
]),
12811281
]);
12821282

1283+
static const mathBlockKatexNegativeMarginsOnVlistRow = ContentExample(
1284+
'math block, KaTeX negative margins on a vlist row',
1285+
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2224918
1286+
'```math\nX_n\n```',
1287+
'<p>'
1288+
'<span class="katex-display"><span class="katex">'
1289+
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>X</mi><mi>n</mi></msub></mrow><annotation encoding="application/x-tex">X_n</annotation></semantics></math></span>'
1290+
'<span class="katex-html" aria-hidden="true">'
1291+
'<span class="base">'
1292+
'<span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span>'
1293+
'<span class="mord">'
1294+
'<span class="mord mathnormal" style="margin-right:0.07847em;">X</span>'
1295+
'<span class="msupsub">'
1296+
'<span class="vlist-t vlist-t2">'
1297+
'<span class="vlist-r">'
1298+
'<span class="vlist" style="height:0.1514em;">'
1299+
'<span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;">'
1300+
'<span class="pstrut" style="height:2.7em;"></span>'
1301+
'<span class="sizing reset-size6 size3 mtight">'
1302+
'<span class="mord mathnormal mtight">n</span></span></span></span>'
1303+
'<span class="vlist-s">​</span></span>'
1304+
'<span class="vlist-r">'
1305+
'<span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span></p>', [
1306+
MathBlockNode(texSource: 'X_n', nodes: [
1307+
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
1308+
KatexStrutNode(heightEm: 0.8333, verticalAlignEm: -0.15),
1309+
KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
1310+
KatexSpanNode(
1311+
styles: KatexSpanStyles(
1312+
marginRightEm: 0.07847,
1313+
fontFamily: 'KaTeX_Math', fontStyle: KatexSpanFontStyle.italic),
1314+
text: 'X', nodes: null),
1315+
KatexSpanNode(
1316+
styles: KatexSpanStyles(textAlign: KatexSpanTextAlign.left),
1317+
text: null, nodes: [
1318+
KatexVlistNode(rows: [
1319+
KatexVlistRowNode(
1320+
verticalOffsetEm: -2.55 + 2.7,
1321+
node: KatexSpanNode(styles: KatexSpanStyles(), text: null, nodes: [
1322+
KatexNegativeMarginNode(leftOffsetEm: -0.0785, nodes: [
1323+
KatexSpanNode(
1324+
styles: KatexSpanStyles(
1325+
marginRightEm: 0.05,
1326+
// TODO parser should not emit this `marginLeftEm` here because
1327+
// it already generates `KatexNegativeMarginNode` for handling it.
1328+
marginLeftEm: -0.0785),
1329+
text: null, nodes: [
1330+
KatexSpanNode(
1331+
styles: KatexSpanStyles(fontSizeEm: 0.7), // .reset-size6.size3
1332+
text: null, nodes: [
1333+
KatexSpanNode(
1334+
styles: KatexSpanStyles(fontFamily: 'KaTeX_Math', fontStyle: KatexSpanFontStyle.italic),
1335+
text: 'n', nodes: null),
1336+
]),
1337+
]),
1338+
]),
1339+
])),
1340+
]),
1341+
]),
1342+
]),
1343+
]),
1344+
]),
1345+
]);
1346+
12831347
static const imageSingle = ContentExample(
12841348
'single image',
12851349
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Thumbnails/near/1900103
@@ -2376,6 +2440,7 @@ void main() async {
23762440
testParseExample(ContentExample.mathBlockKatexRaisebox);
23772441
testParseExample(ContentExample.mathBlockKatexNegativeMargin);
23782442
testParseExample(ContentExample.mathBlockKatexLogo);
2443+
testParseExample(ContentExample.mathBlockKatexNegativeMarginsOnVlistRow);
23792444

23802445
testParseExample(ContentExample.imageSingle);
23812446
testParseExample(ContentExample.imageSingleNoDimensions);

test/widgets/content_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ void main() {
630630
('E', Offset(31.63, 14.52), Size(14.0, 25.0)),
631631
('X', Offset(43.06, 9.85), Size(15.42, 25.0)),
632632
]),
633+
// TODO re-enable this test when parser fixes a bug where
634+
// it emits negative margin in styles, allowing widget
635+
// code to hit an assert.
636+
(ContentExample.mathBlockKatexNegativeMarginsOnVlistRow, skip: true, [
637+
('X', Offset(0.00, 7.04), Size(17.03, 25.00)),
638+
('n', Offset(17.03, 15.90), Size(8.63, 17.00)),
639+
]),
633640
];
634641

635642
for (final testCase in testCases) {
@@ -659,7 +666,7 @@ void main() {
659666
check(size)
660667
.within(distance: 0.05, from: expectedSize);
661668
}
662-
});
669+
}, skip: testCase.skip);
663670
}
664671
});
665672
});

0 commit comments

Comments
 (0)