@@ -123,13 +123,29 @@ class _KatexParser {
123123 }
124124
125125 List <KatexNode > _parseChildSpans (dom.Element element) {
126- return List .unmodifiable (element.nodes.map ((node) {
127- if (node case dom.Element (localName: 'span' )) {
128- return _parseSpan (node);
129- } else {
126+ var resultSpans = < KatexNode > [];
127+ for (final node in element.nodes.reversed) {
128+ if (node is ! dom.Element || node.localName != 'span' ) {
130129 throw KatexHtmlParseError ();
131130 }
132- }));
131+
132+ final span = _parseSpan (node);
133+ resultSpans.add (span);
134+
135+ if (span is KatexSpanNode ) {
136+ final marginRightEm = span.styles.marginRightEm;
137+ if (marginRightEm != null && marginRightEm.isNegative) {
138+ final previousSpansReversed =
139+ resultSpans.reversed.toList (growable: false );
140+ resultSpans = [];
141+ resultSpans.add (KatexNegativeMarginNode (
142+ marginRightEm: marginRightEm,
143+ nodes: previousSpansReversed));
144+ }
145+ }
146+ }
147+
148+ return resultSpans.reversed.toList (growable: false );
133149 }
134150
135151 static final _resetSizeClassRegExp = RegExp (r'^reset-size(\d\d?)$' );
@@ -477,6 +493,7 @@ class _KatexParser {
477493 final stylesheet = css_parser.parse ('*{$styleStr }' );
478494 if (stylesheet.topLevels case [css_visitor.RuleSet () && final rule]) {
479495 double ? heightEm;
496+ double ? marginRightEm;
480497 double ? topEm;
481498 double ? verticalAlignEm;
482499
@@ -491,6 +508,10 @@ class _KatexParser {
491508 heightEm = _getEm (expression);
492509 if (heightEm != null ) continue ;
493510
511+ case 'margin-right' :
512+ marginRightEm = _getEm (expression);
513+ if (marginRightEm != null ) continue ;
514+
494515 case 'top' :
495516 topEm = _getEm (expression);
496517 if (topEm != null ) continue ;
@@ -510,6 +531,7 @@ class _KatexParser {
510531
511532 return KatexSpanStyles (
512533 heightEm: heightEm,
534+ marginRightEm: marginRightEm,
513535 topEm: topEm,
514536 verticalAlignEm: verticalAlignEm,
515537 );
@@ -546,6 +568,7 @@ enum KatexSpanTextAlign {
546568@immutable
547569class KatexSpanStyles {
548570 final double ? heightEm;
571+ final double ? marginRightEm;
549572 final double ? topEm;
550573 final double ? verticalAlignEm;
551574
@@ -557,6 +580,7 @@ class KatexSpanStyles {
557580
558581 const KatexSpanStyles ({
559582 this .heightEm,
583+ this .marginRightEm,
560584 this .topEm,
561585 this .verticalAlignEm,
562586 this .fontFamily,
@@ -570,6 +594,7 @@ class KatexSpanStyles {
570594 int get hashCode => Object .hash (
571595 'KatexSpanStyles' ,
572596 heightEm,
597+ marginRightEm,
573598 topEm,
574599 verticalAlignEm,
575600 fontFamily,
@@ -583,6 +608,7 @@ class KatexSpanStyles {
583608 bool operator == (Object other) {
584609 return other is KatexSpanStyles &&
585610 other.heightEm == heightEm &&
611+ other.marginRightEm == marginRightEm &&
586612 other.topEm == topEm &&
587613 other.verticalAlignEm == verticalAlignEm &&
588614 other.fontFamily == fontFamily &&
@@ -596,6 +622,7 @@ class KatexSpanStyles {
596622 String toString () {
597623 final args = < String > [];
598624 if (heightEm != null ) args.add ('heightEm: $heightEm ' );
625+ if (marginRightEm != null ) args.add ('marginRightEm: $marginRightEm ' );
599626 if (topEm != null ) args.add ('topEm: $topEm ' );
600627 if (verticalAlignEm != null ) args.add ('verticalAlignEm: $verticalAlignEm ' );
601628 if (fontFamily != null ) args.add ('fontFamily: $fontFamily ' );
@@ -609,6 +636,7 @@ class KatexSpanStyles {
609636 KatexSpanStyles merge (KatexSpanStyles other) {
610637 return KatexSpanStyles (
611638 heightEm: other.heightEm ?? heightEm,
639+ marginRightEm: other.marginRightEm ?? marginRightEm,
612640 topEm: other.topEm ?? topEm,
613641 verticalAlignEm: other.verticalAlignEm ?? verticalAlignEm,
614642 fontFamily: other.fontFamily ?? fontFamily,
0 commit comments