@@ -637,6 +637,7 @@ class _KatexParser {
637
637
marginLeftEm: _takeStyleEm (inlineStyles, 'margin-left' ),
638
638
marginRightEm: _takeStyleEm (inlineStyles, 'margin-right' ),
639
639
color: _takeStyleColor (inlineStyles, 'color' ),
640
+ position: _takeStylePosition (inlineStyles, 'position' ),
640
641
// TODO handle more CSS properties
641
642
);
642
643
if (inlineStyles != null && inlineStyles.isNotEmpty) {
@@ -646,10 +647,10 @@ class _KatexParser {
646
647
_hasError = true ;
647
648
}
648
649
}
649
- // Currently, we expect `top` to only be inside a vlist, and
650
- // we handle that case separately above .
651
- if (styles.topEm != null ) {
652
- throw _KatexHtmlParseError ( 'unsupported inline CSS property: top' );
650
+ if (styles.topEm != null && styles.position != KatexSpanPosition .relative) {
651
+ // The meaning of `top` would be different without `position: relative` .
652
+ throw _KatexHtmlParseError (
653
+ 'unsupported inline CSS property " top" given "position: ${ styles . position }" ' );
653
654
}
654
655
655
656
String ? text;
@@ -771,6 +772,34 @@ class _KatexParser {
771
772
_hasError = true ;
772
773
return null ;
773
774
}
775
+
776
+ /// Remove the given property from the given style map,
777
+ /// and parse as a CSS position value.
778
+ ///
779
+ /// If the property is present but is not a valid CSS position value,
780
+ /// record an error and return null.
781
+ ///
782
+ /// If the property is absent, return null with no error.
783
+ ///
784
+ /// If the map is null, treat it as empty.
785
+ ///
786
+ /// To produce the map this method expects, see [_parseInlineStyles] .
787
+ KatexSpanPosition ? _takeStylePosition (Map <String , css_visitor.Expression >? styles, String property) {
788
+ final expression = styles? .remove (property);
789
+ if (expression == null ) return null ;
790
+ if (expression case css_visitor.LiteralTerm (: final value)) {
791
+ if (value case css_visitor.Identifier (: final name)) {
792
+ if (name == 'relative' ) {
793
+ return KatexSpanPosition .relative;
794
+ }
795
+ }
796
+ }
797
+ assert (debugLog ('KaTeX: Unsupported value for CSS property $property ,'
798
+ ' expected a CSS position value: ${expression .toDebugString ()}' ));
799
+ unsupportedInlineCssProperties.add (property);
800
+ _hasError = true ;
801
+ return null ;
802
+ }
774
803
}
775
804
776
805
enum KatexSpanFontWeight {
@@ -788,6 +817,10 @@ enum KatexSpanTextAlign {
788
817
right,
789
818
}
790
819
820
+ enum KatexSpanPosition {
821
+ relative,
822
+ }
823
+
791
824
class KatexSpanColor {
792
825
const KatexSpanColor (this .r, this .g, this .b, this .a);
793
826
@@ -840,6 +873,7 @@ class KatexSpanStyles {
840
873
final KatexSpanTextAlign ? textAlign;
841
874
842
875
final KatexSpanColor ? color;
876
+ final KatexSpanPosition ? position;
843
877
844
878
const KatexSpanStyles ({
845
879
this .widthEm,
@@ -853,6 +887,7 @@ class KatexSpanStyles {
853
887
this .fontStyle,
854
888
this .textAlign,
855
889
this .color,
890
+ this .position,
856
891
});
857
892
858
893
@override
@@ -869,6 +904,7 @@ class KatexSpanStyles {
869
904
fontStyle,
870
905
textAlign,
871
906
color,
907
+ position,
872
908
);
873
909
874
910
@override
@@ -884,7 +920,8 @@ class KatexSpanStyles {
884
920
other.fontWeight == fontWeight &&
885
921
other.fontStyle == fontStyle &&
886
922
other.textAlign == textAlign &&
887
- other.color == color;
923
+ other.color == color &&
924
+ other.position == position;
888
925
}
889
926
890
927
@override
@@ -901,6 +938,7 @@ class KatexSpanStyles {
901
938
if (fontStyle != null ) args.add ('fontStyle: $fontStyle ' );
902
939
if (textAlign != null ) args.add ('textAlign: $textAlign ' );
903
940
if (color != null ) args.add ('color: $color ' );
941
+ if (position != null ) args.add ('position: $position ' );
904
942
return '${objectRuntimeType (this , 'KatexSpanStyles' )}(${args .join (', ' )})' ;
905
943
}
906
944
@@ -917,6 +955,7 @@ class KatexSpanStyles {
917
955
bool fontStyle = true ,
918
956
bool textAlign = true ,
919
957
bool color = true ,
958
+ bool position = true ,
920
959
}) {
921
960
return KatexSpanStyles (
922
961
widthEm: widthEm ? this .widthEm : null ,
@@ -930,6 +969,7 @@ class KatexSpanStyles {
930
969
fontStyle: fontStyle ? this .fontStyle : null ,
931
970
textAlign: textAlign ? this .textAlign : null ,
932
971
color: color ? this .color : null ,
972
+ position: position ? this .position : null ,
933
973
);
934
974
}
935
975
}
0 commit comments