@@ -637,6 +637,7 @@ class _KatexParser {
637637 marginLeftEm: _takeStyleEm (inlineStyles, 'margin-left' ),
638638 marginRightEm: _takeStyleEm (inlineStyles, 'margin-right' ),
639639 color: _takeStyleColor (inlineStyles, 'color' ),
640+ position: _takeStylePosition (inlineStyles, 'position' ),
640641 // TODO handle more CSS properties
641642 );
642643 if (inlineStyles != null && inlineStyles.isNotEmpty) {
@@ -646,10 +647,10 @@ class _KatexParser {
646647 _hasError = true ;
647648 }
648649 }
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 }" ' );
653654 }
654655
655656 String ? text;
@@ -771,6 +772,34 @@ class _KatexParser {
771772 _hasError = true ;
772773 return null ;
773774 }
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+ }
774803}
775804
776805enum KatexSpanFontWeight {
@@ -788,6 +817,10 @@ enum KatexSpanTextAlign {
788817 right,
789818}
790819
820+ enum KatexSpanPosition {
821+ relative,
822+ }
823+
791824class KatexSpanColor {
792825 const KatexSpanColor (this .r, this .g, this .b, this .a);
793826
@@ -840,6 +873,7 @@ class KatexSpanStyles {
840873 final KatexSpanTextAlign ? textAlign;
841874
842875 final KatexSpanColor ? color;
876+ final KatexSpanPosition ? position;
843877
844878 const KatexSpanStyles ({
845879 this .widthEm,
@@ -853,6 +887,7 @@ class KatexSpanStyles {
853887 this .fontStyle,
854888 this .textAlign,
855889 this .color,
890+ this .position,
856891 });
857892
858893 @override
@@ -869,6 +904,7 @@ class KatexSpanStyles {
869904 fontStyle,
870905 textAlign,
871906 color,
907+ position,
872908 );
873909
874910 @override
@@ -884,7 +920,8 @@ class KatexSpanStyles {
884920 other.fontWeight == fontWeight &&
885921 other.fontStyle == fontStyle &&
886922 other.textAlign == textAlign &&
887- other.color == color;
923+ other.color == color &&
924+ other.position == position;
888925 }
889926
890927 @override
@@ -901,6 +938,7 @@ class KatexSpanStyles {
901938 if (fontStyle != null ) args.add ('fontStyle: $fontStyle ' );
902939 if (textAlign != null ) args.add ('textAlign: $textAlign ' );
903940 if (color != null ) args.add ('color: $color ' );
941+ if (position != null ) args.add ('position: $position ' );
904942 return '${objectRuntimeType (this , 'KatexSpanStyles' )}(${args .join (', ' )})' ;
905943 }
906944
@@ -917,6 +955,7 @@ class KatexSpanStyles {
917955 bool fontStyle = true ,
918956 bool textAlign = true ,
919957 bool color = true ,
958+ bool position = true ,
920959 }) {
921960 return KatexSpanStyles (
922961 widthEm: widthEm ? this .widthEm : null ,
@@ -930,6 +969,7 @@ class KatexSpanStyles {
930969 fontStyle: fontStyle ? this .fontStyle : null ,
931970 textAlign: textAlign ? this .textAlign : null ,
932971 color: color ? this .color : null ,
972+ position: position ? this .position : null ,
933973 );
934974 }
935975}
0 commit comments