@@ -140,6 +140,108 @@ class _KatexParser {
140
140
141
141
final spanClasses = List <String >.unmodifiable (element.className.split (' ' ));
142
142
143
+ if (element case dom.Element (localName: 'span' , : final className)
144
+ when className.startsWith ('vlist' )) {
145
+ switch (element) {
146
+ case dom.Element (
147
+ localName: 'span' ,
148
+ className: 'vlist-t' ,
149
+ attributes: final attributesVlistT,
150
+ nodes: [
151
+ dom.Element (
152
+ localName: 'span' ,
153
+ className: 'vlist-r' ,
154
+ attributes: final attributesVlistR,
155
+ nodes: [
156
+ dom.Element (
157
+ localName: 'span' ,
158
+ className: 'vlist' ,
159
+ nodes: [
160
+ dom.Element (
161
+ localName: 'span' ,
162
+ className: '' ,
163
+ nodes: [
164
+ dom.Element (localName: 'span' , className: 'pstrut' )
165
+ && final pstrutSpan,
166
+ ...,
167
+ ]) && final innerSpan,
168
+ ]),
169
+ ]),
170
+ ])
171
+ when ! attributesVlistT.containsKey ('style' ) &&
172
+ ! attributesVlistR.containsKey ('style' ):
173
+ // TODO vlist element should only have `height` style, which we ignore.
174
+
175
+ var styles = _parseSpanInlineStyles (innerSpan)! ;
176
+ final topEm = styles.topEm ?? 0 ;
177
+
178
+ final pstrutStyles = _parseSpanInlineStyles (pstrutSpan)! ;
179
+ final pstrutHeight = pstrutStyles.heightEm ?? 0 ;
180
+
181
+ // TODO handle negative right-margin inline style on row nodes.
182
+ return KatexVlistNode (rows: [
183
+ KatexVlistRowNode (
184
+ verticalOffsetEm: topEm + pstrutHeight,
185
+ nodes: _parseChildSpans (innerSpan)),
186
+ ]);
187
+
188
+ case dom.Element (
189
+ localName: 'span' ,
190
+ className: 'vlist-t vlist-t2' ,
191
+ attributes: final attributesVlistT,
192
+ nodes: [
193
+ dom.Element (
194
+ localName: 'span' ,
195
+ className: 'vlist-r' ,
196
+ attributes: final attributesVlistR,
197
+ nodes: [
198
+ dom.Element (
199
+ localName: 'span' ,
200
+ className: 'vlist' ,
201
+ nodes: [...]) && final vlist1,
202
+ dom.Element (localName: 'span' , className: 'vlist-s' ),
203
+ ]),
204
+ dom.Element (localName: 'span' , className: 'vlist-r' , nodes: [
205
+ dom.Element (localName: 'span' , className: 'vlist' , nodes: [
206
+ dom.Element (localName: 'span' , className: '' , nodes: []),
207
+ ])
208
+ ]),
209
+ ])
210
+ when ! attributesVlistT.containsKey ('style' ) &&
211
+ ! attributesVlistR.containsKey ('style' ):
212
+ // TODO Ensure both should only have a `height` style.
213
+
214
+ final rows = < KatexVlistRowNode > [];
215
+
216
+ for (final innerSpan in vlist1.nodes) {
217
+ if (innerSpan case dom.Element (
218
+ localName: 'span' ,
219
+ className: '' ,
220
+ nodes: [
221
+ dom.Element (localName: 'span' , className: 'pstrut' ) &&
222
+ final pstrutSpan,
223
+ ...,
224
+ ])) {
225
+ final styles = _parseSpanInlineStyles (innerSpan)! ;
226
+ final topEm = styles.topEm ?? 0 ;
227
+
228
+ final pstrutStyles = _parseSpanInlineStyles (pstrutSpan)! ;
229
+ final pstrutHeight = pstrutStyles.heightEm ?? 0 ;
230
+
231
+ // TODO handle negative right-margin inline style on row nodes.
232
+ rows.add (KatexVlistRowNode (
233
+ verticalOffsetEm: topEm + pstrutHeight,
234
+ nodes: _parseChildSpans (innerSpan)));
235
+ }
236
+ }
237
+
238
+ return KatexVlistNode (rows: rows);
239
+
240
+ default :
241
+ throw KatexHtmlParseError ();
242
+ }
243
+ }
244
+
143
245
// Aggregate the CSS styles that apply, in the same order as the CSS
144
246
// classes specified for this span, mimicking the behaviour on web.
145
247
//
@@ -406,7 +508,7 @@ class _KatexParser {
406
508
407
509
final inlineStyles = _parseSpanInlineStyles (element);
408
510
409
- return KatexNode (
511
+ return KatexSpanNode (
410
512
styles: inlineStyles != null
411
513
? styles.merge (inlineStyles)
412
514
: styles,
@@ -422,6 +524,7 @@ class _KatexParser {
422
524
final stylesheet = css_parser.parse ('*{$styleStr }' );
423
525
if (stylesheet.topLevels case [css_visitor.RuleSet () && final rule]) {
424
526
double ? heightEm;
527
+ double ? topEm;
425
528
double ? verticalAlignEm;
426
529
427
530
for (final declaration in rule.declarationGroup.declarations) {
@@ -435,6 +538,10 @@ class _KatexParser {
435
538
heightEm = _getEm (expression);
436
539
if (heightEm != null ) continue ;
437
540
541
+ case 'top' :
542
+ topEm = _getEm (expression);
543
+ if (topEm != null ) continue ;
544
+
438
545
case 'vertical-align' :
439
546
verticalAlignEm = _getEm (expression);
440
547
if (verticalAlignEm != null ) continue ;
@@ -450,6 +557,7 @@ class _KatexParser {
450
557
451
558
return KatexSpanStyles (
452
559
heightEm: heightEm,
560
+ topEm: topEm,
453
561
verticalAlignEm: verticalAlignEm,
454
562
);
455
563
} else {
@@ -484,6 +592,7 @@ enum KatexSpanTextAlign {
484
592
485
593
class KatexSpanStyles {
486
594
double ? heightEm;
595
+ double ? topEm;
487
596
double ? verticalAlignEm;
488
597
489
598
String ? fontFamily;
@@ -494,6 +603,7 @@ class KatexSpanStyles {
494
603
495
604
KatexSpanStyles ({
496
605
this .heightEm,
606
+ this .topEm,
497
607
this .verticalAlignEm,
498
608
this .fontFamily,
499
609
this .fontSizeEm,
@@ -506,6 +616,7 @@ class KatexSpanStyles {
506
616
int get hashCode => Object .hash (
507
617
'KatexSpanStyles' ,
508
618
heightEm,
619
+ topEm,
509
620
verticalAlignEm,
510
621
fontFamily,
511
622
fontSizeEm,
@@ -518,6 +629,7 @@ class KatexSpanStyles {
518
629
bool operator == (Object other) {
519
630
return other is KatexSpanStyles &&
520
631
other.heightEm == heightEm &&
632
+ other.topEm == topEm &&
521
633
other.verticalAlignEm == verticalAlignEm &&
522
634
other.fontFamily == fontFamily &&
523
635
other.fontSizeEm == fontSizeEm &&
@@ -530,6 +642,7 @@ class KatexSpanStyles {
530
642
String toString () {
531
643
final args = < String > [];
532
644
if (heightEm != null ) args.add ('heightEm: $heightEm ' );
645
+ if (topEm != null ) args.add ('topEm: $topEm ' );
533
646
if (verticalAlignEm != null ) args.add ('verticalAlignEm: $verticalAlignEm ' );
534
647
if (fontFamily != null ) args.add ('fontFamily: $fontFamily ' );
535
648
if (fontSizeEm != null ) args.add ('fontSizeEm: $fontSizeEm ' );
@@ -542,6 +655,7 @@ class KatexSpanStyles {
542
655
KatexSpanStyles merge (KatexSpanStyles other) {
543
656
return KatexSpanStyles (
544
657
heightEm: other.heightEm ?? heightEm,
658
+ topEm: other.topEm ?? topEm,
545
659
verticalAlignEm: other.verticalAlignEm ?? verticalAlignEm,
546
660
fontFamily: other.fontFamily ?? fontFamily,
547
661
fontSizeEm: other.fontSizeEm ?? fontSizeEm,
0 commit comments