@@ -583,6 +583,7 @@ class _KatexParser {
583
583
double ? topEm;
584
584
double ? marginRightEm;
585
585
double ? marginLeftEm;
586
+ KatexSpanPosition ? position;
586
587
587
588
for (final declaration in rule.declarationGroup.declarations) {
588
589
if (declaration case css_visitor.Declaration (
@@ -616,6 +617,13 @@ class _KatexParser {
616
617
if (marginLeftEm < 0 ) throw _KatexHtmlParseError ();
617
618
continue ;
618
619
}
620
+
621
+ case 'position' :
622
+ position = switch (_getLiteral (expression)) {
623
+ 'relative' => KatexSpanPosition .relative,
624
+ _ => null ,
625
+ };
626
+ if (position != null ) continue ;
619
627
}
620
628
621
629
// TODO handle more CSS properties
@@ -634,6 +642,7 @@ class _KatexParser {
634
642
verticalAlignEm: verticalAlignEm,
635
643
marginRightEm: marginRightEm,
636
644
marginLeftEm: marginLeftEm,
645
+ position: position,
637
646
);
638
647
} else {
639
648
throw _KatexHtmlParseError ();
@@ -650,6 +659,17 @@ class _KatexParser {
650
659
}
651
660
return null ;
652
661
}
662
+
663
+ /// Returns the CSS literal string value if the given [expression] is
664
+ /// actually a literal expression, else returns null.
665
+ String ? _getLiteral (css_visitor.Expression expression) {
666
+ if (expression case css_visitor.LiteralTerm (: final value)) {
667
+ if (value case css_visitor.Identifier (: final name)) {
668
+ return name;
669
+ }
670
+ }
671
+ return null ;
672
+ }
653
673
}
654
674
655
675
enum KatexSpanFontWeight {
@@ -667,6 +687,10 @@ enum KatexSpanTextAlign {
667
687
right,
668
688
}
669
689
690
+ enum KatexSpanPosition {
691
+ relative,
692
+ }
693
+
670
694
@immutable
671
695
class KatexSpanStyles {
672
696
final double ? heightEm;
@@ -683,6 +707,8 @@ class KatexSpanStyles {
683
707
final KatexSpanFontStyle ? fontStyle;
684
708
final KatexSpanTextAlign ? textAlign;
685
709
710
+ final KatexSpanPosition ? position;
711
+
686
712
const KatexSpanStyles ({
687
713
this .heightEm,
688
714
this .verticalAlignEm,
@@ -694,6 +720,7 @@ class KatexSpanStyles {
694
720
this .fontWeight,
695
721
this .fontStyle,
696
722
this .textAlign,
723
+ this .position,
697
724
});
698
725
699
726
@override
@@ -709,6 +736,7 @@ class KatexSpanStyles {
709
736
fontWeight,
710
737
fontStyle,
711
738
textAlign,
739
+ position,
712
740
);
713
741
714
742
@override
@@ -723,7 +751,8 @@ class KatexSpanStyles {
723
751
other.fontSizeEm == fontSizeEm &&
724
752
other.fontWeight == fontWeight &&
725
753
other.fontStyle == fontStyle &&
726
- other.textAlign == textAlign;
754
+ other.textAlign == textAlign &&
755
+ other.position == position;
727
756
}
728
757
729
758
@override
@@ -739,6 +768,7 @@ class KatexSpanStyles {
739
768
if (fontWeight != null ) args.add ('fontWeight: $fontWeight ' );
740
769
if (fontStyle != null ) args.add ('fontStyle: $fontStyle ' );
741
770
if (textAlign != null ) args.add ('textAlign: $textAlign ' );
771
+ if (position != null ) args.add ('position: $position ' );
742
772
return '${objectRuntimeType (this , 'KatexSpanStyles' )}(${args .join (', ' )})' ;
743
773
}
744
774
@@ -761,6 +791,7 @@ class KatexSpanStyles {
761
791
fontStyle: other.fontStyle ?? fontStyle,
762
792
fontWeight: other.fontWeight ?? fontWeight,
763
793
textAlign: other.textAlign ?? textAlign,
794
+ position: other.position ?? position,
764
795
);
765
796
}
766
797
@@ -775,6 +806,7 @@ class KatexSpanStyles {
775
806
bool fontWeight = true ,
776
807
bool fontStyle = true ,
777
808
bool textAlign = true ,
809
+ bool position = true ,
778
810
}) {
779
811
return KatexSpanStyles (
780
812
heightEm: heightEm ? this .heightEm : null ,
@@ -787,6 +819,7 @@ class KatexSpanStyles {
787
819
fontWeight: fontWeight ? this .fontWeight : null ,
788
820
fontStyle: fontStyle ? this .fontStyle : null ,
789
821
textAlign: textAlign ? this .textAlign : null ,
822
+ position: position ? this .position : null ,
790
823
);
791
824
}
792
825
}
0 commit comments