@@ -133,6 +133,83 @@ class _KatexParser {
133
133
KatexNode _parseSpan (dom.Element element) {
134
134
// TODO maybe check if the sequence of ancestors matter for spans.
135
135
136
+ if (element.className.startsWith ('vlist' )) {
137
+ if (element case dom.Element (
138
+ localName: 'span' ,
139
+ className: 'vlist-t' || 'vlist-t vlist-t2' ,
140
+ nodes: [...],
141
+ ) && final vlistT) {
142
+ if (vlistT.attributes.containsKey ('style' )) throw KatexHtmlParseError ();
143
+
144
+ final hasTwoVlistR = vlistT.className == 'vlist-t vlist-t2' ;
145
+ if (! hasTwoVlistR && vlistT.nodes.length != 1 ) throw KatexHtmlParseError ();
146
+
147
+ if (hasTwoVlistR) {
148
+ if (vlistT.nodes case [
149
+ _,
150
+ dom.Element (localName: 'span' , className: 'vlist-r' , nodes: [
151
+ dom.Element (localName: 'span' , className: 'vlist' , nodes: [
152
+ dom.Element (localName: 'span' , className: '' , nodes: []),
153
+ ]),
154
+ ]),
155
+ ]) {
156
+ // Do nothing.
157
+ } else {
158
+ throw KatexHtmlParseError ();
159
+ }
160
+ }
161
+
162
+ if (vlistT.nodes.first
163
+ case dom.Element (localName: 'span' , className: 'vlist-r' ) &&
164
+ final vlistR) {
165
+ if (vlistR.attributes.containsKey ('style' )) throw KatexHtmlParseError ();
166
+
167
+ if (vlistR.nodes.first
168
+ case dom.Element (localName: 'span' , className: 'vlist' ) &&
169
+ final vlist) {
170
+ final rows = < KatexVlistRowNode > [];
171
+
172
+ for (final innerSpan in vlist.nodes) {
173
+ if (innerSpan case dom.Element (
174
+ localName: 'span' ,
175
+ className: '' ,
176
+ nodes: [
177
+ dom.Element (localName: 'span' , className: 'pstrut' ) &&
178
+ final pstrutSpan,
179
+ ...final otherSpans,
180
+ ],
181
+ )) {
182
+ var styles = _parseSpanInlineStyles (innerSpan)! ;
183
+ final topEm = styles.topEm ?? 0 ;
184
+
185
+ styles = styles.filter (topEm: false );
186
+
187
+ final pstrutStyles = _parseSpanInlineStyles (pstrutSpan)! ;
188
+ final pstrutHeight = pstrutStyles.heightEm ?? 0 ;
189
+
190
+ rows.add (KatexVlistRowNode (
191
+ verticalOffsetEm: topEm + pstrutHeight,
192
+ node: KatexSpanNode (
193
+ styles: styles,
194
+ text: null ,
195
+ nodes: _parseChildSpans (otherSpans))));
196
+ } else {
197
+ throw KatexHtmlParseError ();
198
+ }
199
+ }
200
+
201
+ return KatexVlistNode (rows: rows);
202
+ } else {
203
+ throw KatexHtmlParseError ();
204
+ }
205
+ } else {
206
+ throw KatexHtmlParseError ();
207
+ }
208
+ } else {
209
+ throw KatexHtmlParseError ();
210
+ }
211
+ }
212
+
136
213
// Aggregate the CSS styles that apply, in the same order as the CSS
137
214
// classes specified for this span, mimicking the behaviour on web.
138
215
//
@@ -141,7 +218,9 @@ class _KatexParser {
141
218
// https://github.com/KaTeX/KaTeX/blob/2fe1941b/src/styles/katex.scss
142
219
// A copy of class definition (where possible) is accompanied in a comment
143
220
// with each case statement to keep track of updates.
144
- final spanClasses = List <String >.unmodifiable (element.className.split (' ' ));
221
+ final spanClasses = element.className != ''
222
+ ? List <String >.unmodifiable (element.className.split (' ' ))
223
+ : const < String > [];
145
224
String ? fontFamily;
146
225
double ? fontSizeEm;
147
226
KatexSpanFontWeight ? fontWeight;
@@ -567,6 +646,32 @@ class KatexSpanStyles {
567
646
textAlign: other.textAlign ?? textAlign,
568
647
);
569
648
}
649
+
650
+ KatexSpanStyles filter ({
651
+ bool heightEm = true ,
652
+ bool verticalAlignEm = true ,
653
+ bool topEm = true ,
654
+ bool marginRightEm = true ,
655
+ bool marginLeftEm = true ,
656
+ bool fontFamily = true ,
657
+ bool fontSizeEm = true ,
658
+ bool fontWeight = true ,
659
+ bool fontStyle = true ,
660
+ bool textAlign = true ,
661
+ }) {
662
+ return KatexSpanStyles (
663
+ heightEm: heightEm ? this .heightEm : null ,
664
+ verticalAlignEm: verticalAlignEm ? this .verticalAlignEm : null ,
665
+ topEm: topEm ? this .topEm : null ,
666
+ marginRightEm: marginRightEm ? this .marginRightEm : null ,
667
+ marginLeftEm: marginLeftEm ? this .marginLeftEm : null ,
668
+ fontFamily: fontFamily ? this .fontFamily : null ,
669
+ fontSizeEm: fontSizeEm ? this .fontSizeEm : null ,
670
+ fontWeight: fontWeight ? this .fontWeight : null ,
671
+ fontStyle: fontStyle ? this .fontStyle : null ,
672
+ textAlign: textAlign ? this .textAlign : null ,
673
+ );
674
+ }
570
675
}
571
676
572
677
class KatexHtmlParseError extends Error {
0 commit comments