@@ -123,13 +123,29 @@ class _KatexParser {
123
123
}
124
124
125
125
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' ) {
130
129
throw KatexHtmlParseError ();
131
130
}
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 );
133
149
}
134
150
135
151
static final _resetSizeClassRegExp = RegExp (r'^reset-size(\d\d?)$' );
@@ -477,6 +493,7 @@ class _KatexParser {
477
493
final stylesheet = css_parser.parse ('*{$styleStr }' );
478
494
if (stylesheet.topLevels case [css_visitor.RuleSet () && final rule]) {
479
495
double ? heightEm;
496
+ double ? marginRightEm;
480
497
double ? topEm;
481
498
double ? verticalAlignEm;
482
499
@@ -491,6 +508,10 @@ class _KatexParser {
491
508
heightEm = _getEm (expression);
492
509
if (heightEm != null ) continue ;
493
510
511
+ case 'margin-right' :
512
+ marginRightEm = _getEm (expression);
513
+ if (marginRightEm != null ) continue ;
514
+
494
515
case 'top' :
495
516
topEm = _getEm (expression);
496
517
if (topEm != null ) continue ;
@@ -510,6 +531,7 @@ class _KatexParser {
510
531
511
532
return KatexSpanStyles (
512
533
heightEm: heightEm,
534
+ marginRightEm: marginRightEm,
513
535
topEm: topEm,
514
536
verticalAlignEm: verticalAlignEm,
515
537
);
@@ -546,6 +568,7 @@ enum KatexSpanTextAlign {
546
568
@immutable
547
569
class KatexSpanStyles {
548
570
final double ? heightEm;
571
+ final double ? marginRightEm;
549
572
final double ? topEm;
550
573
final double ? verticalAlignEm;
551
574
@@ -557,6 +580,7 @@ class KatexSpanStyles {
557
580
558
581
const KatexSpanStyles ({
559
582
this .heightEm,
583
+ this .marginRightEm,
560
584
this .topEm,
561
585
this .verticalAlignEm,
562
586
this .fontFamily,
@@ -570,6 +594,7 @@ class KatexSpanStyles {
570
594
int get hashCode => Object .hash (
571
595
'KatexSpanStyles' ,
572
596
heightEm,
597
+ marginRightEm,
573
598
topEm,
574
599
verticalAlignEm,
575
600
fontFamily,
@@ -583,6 +608,7 @@ class KatexSpanStyles {
583
608
bool operator == (Object other) {
584
609
return other is KatexSpanStyles &&
585
610
other.heightEm == heightEm &&
611
+ other.marginRightEm == marginRightEm &&
586
612
other.topEm == topEm &&
587
613
other.verticalAlignEm == verticalAlignEm &&
588
614
other.fontFamily == fontFamily &&
@@ -596,6 +622,7 @@ class KatexSpanStyles {
596
622
String toString () {
597
623
final args = < String > [];
598
624
if (heightEm != null ) args.add ('heightEm: $heightEm ' );
625
+ if (marginRightEm != null ) args.add ('marginRightEm: $marginRightEm ' );
599
626
if (topEm != null ) args.add ('topEm: $topEm ' );
600
627
if (verticalAlignEm != null ) args.add ('verticalAlignEm: $verticalAlignEm ' );
601
628
if (fontFamily != null ) args.add ('fontFamily: $fontFamily ' );
@@ -609,6 +636,7 @@ class KatexSpanStyles {
609
636
KatexSpanStyles merge (KatexSpanStyles other) {
610
637
return KatexSpanStyles (
611
638
heightEm: other.heightEm ?? heightEm,
639
+ marginRightEm: other.marginRightEm ?? marginRightEm,
612
640
topEm: other.topEm ?? topEm,
613
641
verticalAlignEm: other.verticalAlignEm ?? verticalAlignEm,
614
642
fontFamily: other.fontFamily ?? fontFamily,
0 commit comments