@@ -514,6 +514,7 @@ class _KatexParser {
514
514
double ? topEm;
515
515
double ? marginRightEm;
516
516
double ? marginLeftEm;
517
+ KatexSpanPosition ? position;
517
518
518
519
for (final declaration in rule.declarationGroup.declarations) {
519
520
if (declaration case css_visitor.Declaration (
@@ -547,6 +548,13 @@ class _KatexParser {
547
548
if (marginLeftEm < 0 ) throw KatexHtmlParseError ();
548
549
continue ;
549
550
}
551
+
552
+ case 'position' :
553
+ position = switch (_getLiteral (expression)) {
554
+ 'relative' => KatexSpanPosition .relative,
555
+ _ => null ,
556
+ };
557
+ if (position != null ) continue ;
550
558
}
551
559
552
560
// TODO handle more CSS properties
@@ -564,6 +572,7 @@ class _KatexParser {
564
572
verticalAlignEm: verticalAlignEm,
565
573
marginRightEm: marginRightEm,
566
574
marginLeftEm: marginLeftEm,
575
+ position: position,
567
576
);
568
577
} else {
569
578
throw KatexHtmlParseError ();
@@ -580,6 +589,17 @@ class _KatexParser {
580
589
}
581
590
return null ;
582
591
}
592
+
593
+ /// Returns the CSS literal string value if the given [expression] is
594
+ /// actually a literal expression, else returns null.
595
+ String ? _getLiteral (css_visitor.Expression expression) {
596
+ if (expression case css_visitor.LiteralTerm (: final value)) {
597
+ if (value case css_visitor.Identifier (: final name)) {
598
+ return name;
599
+ }
600
+ }
601
+ return null ;
602
+ }
583
603
}
584
604
585
605
enum KatexSpanFontWeight {
@@ -597,6 +617,10 @@ enum KatexSpanTextAlign {
597
617
right,
598
618
}
599
619
620
+ enum KatexSpanPosition {
621
+ relative,
622
+ }
623
+
600
624
@immutable
601
625
class KatexSpanStyles {
602
626
final double ? heightEm;
@@ -613,6 +637,8 @@ class KatexSpanStyles {
613
637
final KatexSpanFontStyle ? fontStyle;
614
638
final KatexSpanTextAlign ? textAlign;
615
639
640
+ final KatexSpanPosition ? position;
641
+
616
642
const KatexSpanStyles ({
617
643
this .heightEm,
618
644
this .verticalAlignEm,
@@ -624,6 +650,7 @@ class KatexSpanStyles {
624
650
this .fontWeight,
625
651
this .fontStyle,
626
652
this .textAlign,
653
+ this .position,
627
654
});
628
655
629
656
@override
@@ -639,6 +666,7 @@ class KatexSpanStyles {
639
666
fontWeight,
640
667
fontStyle,
641
668
textAlign,
669
+ position,
642
670
);
643
671
644
672
@override
@@ -653,7 +681,8 @@ class KatexSpanStyles {
653
681
other.fontSizeEm == fontSizeEm &&
654
682
other.fontWeight == fontWeight &&
655
683
other.fontStyle == fontStyle &&
656
- other.textAlign == textAlign;
684
+ other.textAlign == textAlign &&
685
+ other.position == position;
657
686
}
658
687
659
688
@override
@@ -669,6 +698,7 @@ class KatexSpanStyles {
669
698
if (fontWeight != null ) args.add ('fontWeight: $fontWeight ' );
670
699
if (fontStyle != null ) args.add ('fontStyle: $fontStyle ' );
671
700
if (textAlign != null ) args.add ('textAlign: $textAlign ' );
701
+ if (position != null ) args.add ('position: $position ' );
672
702
return '${objectRuntimeType (this , 'KatexSpanStyles' )}(${args .join (', ' )})' ;
673
703
}
674
704
@@ -684,6 +714,7 @@ class KatexSpanStyles {
684
714
fontStyle: other.fontStyle ?? fontStyle,
685
715
fontWeight: other.fontWeight ?? fontWeight,
686
716
textAlign: other.textAlign ?? textAlign,
717
+ position: other.position ?? position,
687
718
);
688
719
}
689
720
@@ -698,6 +729,7 @@ class KatexSpanStyles {
698
729
bool fontWeight = true ,
699
730
bool fontStyle = true ,
700
731
bool textAlign = true ,
732
+ bool position = true ,
701
733
}) {
702
734
return KatexSpanStyles (
703
735
heightEm: heightEm ? this .heightEm : null ,
@@ -710,6 +742,7 @@ class KatexSpanStyles {
710
742
fontWeight: fontWeight ? this .fontWeight : null ,
711
743
fontStyle: fontStyle ? this .fontStyle : null ,
712
744
textAlign: textAlign ? this .textAlign : null ,
745
+ position: position ? this .position : null ,
713
746
);
714
747
}
715
748
}
0 commit comments