Skip to content

Commit 71ae7f2

Browse files
content: Ensure inline styles for big operators in KaTeX content
1 parent 9bb0ed0 commit 71ae7f2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/model/katex.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ class _KatexParser {
514514
_ => throw _KatexHtmlParseError(),
515515
};
516516

517+
// Some .op-symbol spans can have `position: relative` with some
518+
// `top` offset as inline styles. We expect that if position is
519+
// present it is always `relative` and be accompanying with some
520+
// `top` offset.
521+
if (inlineStyles case KatexSpanStyles(
522+
:final position,
523+
:final topEm,
524+
) when position != null) {
525+
if (position != KatexSpanPosition.relative || topEm == null) {
526+
throw _KatexHtmlParseError();
527+
}
528+
}
529+
517530
// TODO handle more classes from katex.scss
518531

519532
case 'mord':

test/model/content_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,37 @@ class ContentExample {
12651265
]),
12661266
]);
12671267

1268+
static const mathBlockKatexBigOperators = ContentExample(
1269+
'math block katex big operators',
1270+
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2203220
1271+
'```math\n\\bigsqcup\n```',
1272+
'<p>'
1273+
'<span class="katex-display"><span class="katex">'
1274+
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo>⨆</mo></mrow><annotation encoding="application/x-tex">\\bigsqcup</annotation></semantics></math></span>'
1275+
'<span class="katex-html" aria-hidden="true">'
1276+
'<span class="base">'
1277+
'<span class="strut" style="height:1.6em;vertical-align:-0.55em;"></span>'
1278+
'<span class="mop op-symbol large-op" style="position:relative;top:0em;">⨆</span></span></span></span></span></p>',
1279+
[
1280+
MathBlockNode(
1281+
texSource: '\\bigsqcup',
1282+
nodes: [
1283+
KatexSpanNode(
1284+
styles: KatexSpanStyles(),
1285+
text: null,
1286+
nodes: [
1287+
KatexStrutNode(heightEm: 1.6, verticalAlignEm: -0.55),
1288+
KatexSpanNode(
1289+
styles: KatexSpanStyles(
1290+
topEm: 0.0,
1291+
fontFamily: 'KaTeX_Size2',
1292+
position: KatexSpanPosition.relative),
1293+
text: '⨆',
1294+
nodes: null),
1295+
]),
1296+
]),
1297+
]);
1298+
12681299
static const imageSingle = ContentExample(
12691300
'single image',
12701301
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Thumbnails/near/1900103
@@ -2341,6 +2372,7 @@ void main() async {
23412372
testParseExample(ContentExample.mathBlockKatexVertical3);
23422373
testParseExample(ContentExample.mathBlockKatexVertical4);
23432374
testParseExample(ContentExample.mathBlockKatexVertical5);
2375+
testParseExample(ContentExample.mathBlockKatexBigOperators);
23442376

23452377
testParseExample(ContentExample.imageSingle);
23462378
testParseExample(ContentExample.imageSingleNoDimensions);

0 commit comments

Comments
 (0)