@@ -631,6 +631,7 @@ class _KatexParser {
631
631
marginLeftEm: _takeStyleEm (inlineStyles, 'margin-left' ),
632
632
marginRightEm: _takeStyleEm (inlineStyles, 'margin-right' ),
633
633
color: _takeStyleColor (inlineStyles, 'color' ),
634
+ position: _takeStylePosition (inlineStyles, 'position' ),
634
635
// TODO handle more CSS properties
635
636
);
636
637
if (inlineStyles != null && inlineStyles.isNotEmpty) {
@@ -642,8 +643,8 @@ class _KatexParser {
642
643
}
643
644
// Currently, we expect `top` to only be inside a vlist, and
644
645
// we handle that case separately above.
645
- if (styles.topEm != null ) {
646
- throw _KatexHtmlParseError ('unsupported inline CSS property: top' );
646
+ if (styles.topEm != null && styles.position != KatexSpanPosition .relative ) {
647
+ throw _KatexHtmlParseError ('unsupported inline CSS property " top", when "position: ${ styles . position }" ' );
647
648
}
648
649
649
650
String ? text;
@@ -765,6 +766,34 @@ class _KatexParser {
765
766
_hasError = true ;
766
767
return null ;
767
768
}
769
+
770
+ /// Remove the given property from the given style map,
771
+ /// and parse as a literal value of CSS position attribute.
772
+ ///
773
+ /// If the property is present but is not a valid literal value of
774
+ /// position attribute, record an error and return null.
775
+ ///
776
+ /// If the property is absent, return null with no error.
777
+ ///
778
+ /// If the map is null, treat it as empty.
779
+ ///
780
+ /// To produce the map this method expects, see [_parseInlineStyles] .
781
+ KatexSpanPosition ? _takeStylePosition (Map <String , css_visitor.Expression >? styles, String property) {
782
+ final expression = styles? .remove (property);
783
+ if (expression == null ) return null ;
784
+ if (expression case css_visitor.LiteralTerm (: final value)) {
785
+ if (value case css_visitor.Identifier (: final name)) {
786
+ if (name == 'relative' ) {
787
+ return KatexSpanPosition .relative;
788
+ }
789
+ }
790
+ }
791
+ assert (debugLog ('KaTeX: Unsupported value for CSS property $property ,'
792
+ ' expected a position literal value: ${expression .toDebugString ()}' ));
793
+ unsupportedInlineCssProperties.add (property);
794
+ _hasError = true ;
795
+ return null ;
796
+ }
768
797
}
769
798
770
799
enum KatexSpanFontWeight {
@@ -782,6 +811,10 @@ enum KatexSpanTextAlign {
782
811
right,
783
812
}
784
813
814
+ enum KatexSpanPosition {
815
+ relative,
816
+ }
817
+
785
818
class KatexSpanColor {
786
819
const KatexSpanColor (this .r, this .g, this .b, this .a);
787
820
@@ -832,6 +865,7 @@ class KatexSpanStyles {
832
865
final KatexSpanTextAlign ? textAlign;
833
866
834
867
final KatexSpanColor ? color;
868
+ final KatexSpanPosition ? position;
835
869
836
870
const KatexSpanStyles ({
837
871
this .heightEm,
@@ -844,6 +878,7 @@ class KatexSpanStyles {
844
878
this .fontStyle,
845
879
this .textAlign,
846
880
this .color,
881
+ this .position,
847
882
});
848
883
849
884
@override
@@ -859,6 +894,7 @@ class KatexSpanStyles {
859
894
fontStyle,
860
895
textAlign,
861
896
color,
897
+ position,
862
898
);
863
899
864
900
@override
@@ -873,7 +909,8 @@ class KatexSpanStyles {
873
909
other.fontWeight == fontWeight &&
874
910
other.fontStyle == fontStyle &&
875
911
other.textAlign == textAlign &&
876
- other.color == color;
912
+ other.color == color &&
913
+ other.position == position;
877
914
}
878
915
879
916
@override
@@ -889,6 +926,7 @@ class KatexSpanStyles {
889
926
if (fontStyle != null ) args.add ('fontStyle: $fontStyle ' );
890
927
if (textAlign != null ) args.add ('textAlign: $textAlign ' );
891
928
if (color != null ) args.add ('color: $color ' );
929
+ if (position != null ) args.add ('position: $position ' );
892
930
return '${objectRuntimeType (this , 'KatexSpanStyles' )}(${args .join (', ' )})' ;
893
931
}
894
932
@@ -904,6 +942,7 @@ class KatexSpanStyles {
904
942
bool fontStyle = true ,
905
943
bool textAlign = true ,
906
944
bool color = true ,
945
+ bool position = true ,
907
946
}) {
908
947
return KatexSpanStyles (
909
948
heightEm: heightEm ? this .heightEm : null ,
@@ -916,6 +955,7 @@ class KatexSpanStyles {
916
955
fontStyle: fontStyle ? this .fontStyle : null ,
917
956
textAlign: textAlign ? this .textAlign : null ,
918
957
color: color ? this .color : null ,
958
+ position: position ? this .position : null ,
919
959
);
920
960
}
921
961
}
0 commit comments