@@ -612,23 +612,32 @@ class _KatexParser {
612
612
_hasError = true ;
613
613
}
614
614
}
615
- final classStyles = KatexSpanStyles (
615
+
616
+ final inlineStyles = _parseInlineStyles (element);
617
+ final styles = KatexSpanStyles (
616
618
fontFamily: fontFamily,
617
619
fontSizeEm: fontSizeEm,
618
620
fontWeight: fontWeight,
619
621
fontStyle: fontStyle,
620
622
textAlign: textAlign,
623
+ heightEm: _takeStyleEm (inlineStyles, 'height' ),
624
+ topEm: _takeStyleEm (inlineStyles, 'top' ),
625
+ marginLeftEm: _takeStyleEm (inlineStyles, 'margin-left' ),
626
+ marginRightEm: _takeStyleEm (inlineStyles, 'margin-right' ),
627
+ // TODO handle more CSS properties
621
628
);
622
- final inlineStyles = _parseSpanInlineStyles (element);
623
- if (inlineStyles != null ) {
624
- // Currently, we expect `top` to only be inside a vlist, and
625
- // we handle that case separately above.
626
- if (inlineStyles.topEm != null ) {
627
- throw _KatexHtmlParseError ('unsupported inline CSS property: top' );
629
+ if (inlineStyles != null && inlineStyles.isNotEmpty) {
630
+ for (final property in inlineStyles.keys) {
631
+ assert (debugLog ('KaTeX: Unexpected inline CSS property: $property ' ));
632
+ unsupportedInlineCssProperties.add (property);
633
+ _hasError = true ;
628
634
}
629
635
}
630
- final styles = inlineStyles == null ? classStyles
631
- : classStyles.merge (inlineStyles);
636
+ // Currently, we expect `top` to only be inside a vlist, and
637
+ // we handle that case separately above.
638
+ if (styles.topEm != null ) {
639
+ throw _KatexHtmlParseError ('unsupported inline CSS property: top' );
640
+ }
632
641
633
642
String ? text;
634
643
List <KatexNode >? spans;
@@ -646,34 +655,6 @@ class _KatexParser {
646
655
debugHtmlNode: debugHtmlNode);
647
656
}
648
657
649
- /// Parse the inline CSS styles from the given element,
650
- /// and look for the styles we know how to interpret for a generic KaTeX span.
651
- ///
652
- /// TODO: This has a number of call sites that aren't acting on a generic
653
- /// KaTeX span, but instead on spans in particular roles where we have
654
- /// much more specific expectations on the inline styles.
655
- /// For those, switch to [_parseInlineStyles] and inspect the styles directly.
656
- KatexSpanStyles ? _parseSpanInlineStyles (dom.Element element) {
657
- final declarations = _parseInlineStyles (element);
658
- if (declarations == null ) return null ;
659
-
660
- final result = KatexSpanStyles (
661
- heightEm: _takeStyleEm (declarations, 'height' ),
662
- topEm: _takeStyleEm (declarations, 'top' ),
663
- marginRightEm: _takeStyleEm (declarations, 'margin-right' ),
664
- marginLeftEm: _takeStyleEm (declarations, 'margin-left' ),
665
- // TODO handle more CSS properties
666
- );
667
-
668
- for (final property in declarations.keys) {
669
- assert (debugLog ('KaTeX: Unexpected inline CSS property: $property ' ));
670
- unsupportedInlineCssProperties.add (property);
671
- _hasError = true ;
672
- }
673
-
674
- return result;
675
- }
676
-
677
658
/// Parse the inline CSS styles from the given element.
678
659
///
679
660
/// To interpret the resulting map, consider [_takeStyleEm] .
@@ -820,27 +801,6 @@ class KatexSpanStyles {
820
801
return '${objectRuntimeType (this , 'KatexSpanStyles' )}(${args .join (', ' )})' ;
821
802
}
822
803
823
- /// Creates a new [KatexSpanStyles] with current and [other] 's styles merged.
824
- ///
825
- /// The styles in [other] take precedence and any missing styles in [other]
826
- /// are filled in with current styles, if present.
827
- ///
828
- /// This similar to the behaviour of [TextStyle.merge] , if the given style
829
- /// had `inherit` set to true.
830
- KatexSpanStyles merge (KatexSpanStyles other) {
831
- return KatexSpanStyles (
832
- heightEm: other.heightEm ?? heightEm,
833
- topEm: other.topEm ?? topEm,
834
- marginRightEm: other.marginRightEm ?? marginRightEm,
835
- marginLeftEm: other.marginLeftEm ?? marginLeftEm,
836
- fontFamily: other.fontFamily ?? fontFamily,
837
- fontSizeEm: other.fontSizeEm ?? fontSizeEm,
838
- fontStyle: other.fontStyle ?? fontStyle,
839
- fontWeight: other.fontWeight ?? fontWeight,
840
- textAlign: other.textAlign ?? textAlign,
841
- );
842
- }
843
-
844
804
KatexSpanStyles filter ({
845
805
bool heightEm = true ,
846
806
bool verticalAlignEm = true ,
0 commit comments