@@ -136,8 +136,6 @@ class _KatexParser {
136
136
KatexNode _parseSpan (dom.Element element) {
137
137
// TODO maybe check if the sequence of ancestors matter for spans.
138
138
139
- final spanClasses = List <String >.unmodifiable (element.className.split (' ' ));
140
-
141
139
// Aggregate the CSS styles that apply, in the same order as the CSS
142
140
// classes specified for this span, mimicking the behaviour on web.
143
141
//
@@ -146,7 +144,12 @@ class _KatexParser {
146
144
// https://github.com/KaTeX/KaTeX/blob/2fe1941b/src/styles/katex.scss
147
145
// A copy of class definition (where possible) is accompanied in a comment
148
146
// with each case statement to keep track of updates.
149
- var styles = KatexSpanStyles ();
147
+ final spanClasses = List <String >.unmodifiable (element.className.split (' ' ));
148
+ String ? fontFamily;
149
+ double ? fontSizeEm;
150
+ KatexSpanFontWeight ? fontWeight;
151
+ KatexSpanFontStyle ? fontStyle;
152
+ KatexSpanTextAlign ? textAlign;
150
153
var index = 0 ;
151
154
while (index < spanClasses.length) {
152
155
final spanClass = spanClasses[index++ ];
@@ -163,15 +166,15 @@ class _KatexParser {
163
166
164
167
case 'textbf' :
165
168
// .textbf { font-weight: bold; }
166
- styles. fontWeight = KatexSpanFontWeight .bold;
169
+ fontWeight = KatexSpanFontWeight .bold;
167
170
168
171
case 'textit' :
169
172
// .textit { font-style: italic; }
170
- styles. fontStyle = KatexSpanFontStyle .italic;
173
+ fontStyle = KatexSpanFontStyle .italic;
171
174
172
175
case 'textrm' :
173
176
// .textrm { font-family: KaTeX_Main; }
174
- styles. fontFamily = 'KaTeX_Main' ;
177
+ fontFamily = 'KaTeX_Main' ;
175
178
176
179
// case 'textsf':
177
180
// // .textsf { font-family: KaTeX_SansSerif; }
@@ -180,96 +183,96 @@ class _KatexParser {
180
183
181
184
case 'texttt' :
182
185
// .texttt { font-family: KaTeX_Typewriter; }
183
- styles. fontFamily = 'KaTeX_Typewriter' ;
186
+ fontFamily = 'KaTeX_Typewriter' ;
184
187
185
188
case 'mathnormal' :
186
189
// .mathnormal { font-family: KaTeX_Math; font-style: italic; }
187
- styles. fontFamily = 'KaTeX_Math' ;
188
- styles. fontStyle = KatexSpanFontStyle .italic;
190
+ fontFamily = 'KaTeX_Math' ;
191
+ fontStyle = KatexSpanFontStyle .italic;
189
192
190
193
case 'mathit' :
191
194
// .mathit { font-family: KaTeX_Main; font-style: italic; }
192
- styles. fontFamily = 'KaTeX_Main' ;
193
- styles. fontStyle = KatexSpanFontStyle .italic;
195
+ fontFamily = 'KaTeX_Main' ;
196
+ fontStyle = KatexSpanFontStyle .italic;
194
197
195
198
case 'mathrm' :
196
199
// .mathrm { font-style: normal; }
197
- styles. fontStyle = KatexSpanFontStyle .normal;
200
+ fontStyle = KatexSpanFontStyle .normal;
198
201
199
202
case 'mathbf' :
200
203
// .mathbf { font-family: KaTeX_Main; font-weight: bold; }
201
- styles. fontFamily = 'KaTeX_Main' ;
202
- styles. fontWeight = KatexSpanFontWeight .bold;
204
+ fontFamily = 'KaTeX_Main' ;
205
+ fontWeight = KatexSpanFontWeight .bold;
203
206
204
207
case 'boldsymbol' :
205
208
// .boldsymbol { font-family: KaTeX_Math; font-weight: bold; font-style: italic; }
206
- styles. fontFamily = 'KaTeX_Math' ;
207
- styles. fontWeight = KatexSpanFontWeight .bold;
208
- styles. fontStyle = KatexSpanFontStyle .italic;
209
+ fontFamily = 'KaTeX_Math' ;
210
+ fontWeight = KatexSpanFontWeight .bold;
211
+ fontStyle = KatexSpanFontStyle .italic;
209
212
210
213
case 'amsrm' :
211
214
// .amsrm { font-family: KaTeX_AMS; }
212
- styles. fontFamily = 'KaTeX_AMS' ;
215
+ fontFamily = 'KaTeX_AMS' ;
213
216
214
217
case 'mathbb' :
215
218
case 'textbb' :
216
219
// .mathbb,
217
220
// .textbb { font-family: KaTeX_AMS; }
218
- styles. fontFamily = 'KaTeX_AMS' ;
221
+ fontFamily = 'KaTeX_AMS' ;
219
222
220
223
case 'mathcal' :
221
224
// .mathcal { font-family: KaTeX_Caligraphic; }
222
- styles. fontFamily = 'KaTeX_Caligraphic' ;
225
+ fontFamily = 'KaTeX_Caligraphic' ;
223
226
224
227
case 'mathfrak' :
225
228
case 'textfrak' :
226
229
// .mathfrak,
227
230
// .textfrak { font-family: KaTeX_Fraktur; }
228
- styles. fontFamily = 'KaTeX_Fraktur' ;
231
+ fontFamily = 'KaTeX_Fraktur' ;
229
232
230
233
case 'mathboldfrak' :
231
234
case 'textboldfrak' :
232
235
// .mathboldfrak,
233
236
// .textboldfrak { font-family: KaTeX_Fraktur; font-weight: bold; }
234
- styles. fontFamily = 'KaTeX_Fraktur' ;
235
- styles. fontWeight = KatexSpanFontWeight .bold;
237
+ fontFamily = 'KaTeX_Fraktur' ;
238
+ fontWeight = KatexSpanFontWeight .bold;
236
239
237
240
case 'mathtt' :
238
241
// .mathtt { font-family: KaTeX_Typewriter; }
239
- styles. fontFamily = 'KaTeX_Typewriter' ;
242
+ fontFamily = 'KaTeX_Typewriter' ;
240
243
241
244
case 'mathscr' :
242
245
case 'textscr' :
243
246
// .mathscr,
244
247
// .textscr { font-family: KaTeX_Script; }
245
- styles. fontFamily = 'KaTeX_Script' ;
248
+ fontFamily = 'KaTeX_Script' ;
246
249
247
250
case 'mathsf' :
248
251
case 'textsf' :
249
252
// .mathsf,
250
253
// .textsf { font-family: KaTeX_SansSerif; }
251
- styles. fontFamily = 'KaTeX_SansSerif' ;
254
+ fontFamily = 'KaTeX_SansSerif' ;
252
255
253
256
case 'mathboldsf' :
254
257
case 'textboldsf' :
255
258
// .mathboldsf,
256
259
// .textboldsf { font-family: KaTeX_SansSerif; font-weight: bold; }
257
- styles. fontFamily = 'KaTeX_SansSerif' ;
258
- styles. fontWeight = KatexSpanFontWeight .bold;
260
+ fontFamily = 'KaTeX_SansSerif' ;
261
+ fontWeight = KatexSpanFontWeight .bold;
259
262
260
263
case 'mathsfit' :
261
264
case 'mathitsf' :
262
265
case 'textitsf' :
263
266
// .mathsfit,
264
267
// .mathitsf,
265
268
// .textitsf { font-family: KaTeX_SansSerif; font-style: italic; }
266
- styles. fontFamily = 'KaTeX_SansSerif' ;
267
- styles. fontStyle = KatexSpanFontStyle .italic;
269
+ fontFamily = 'KaTeX_SansSerif' ;
270
+ fontStyle = KatexSpanFontStyle .italic;
268
271
269
272
case 'mainrm' :
270
273
// .mainrm { font-family: KaTeX_Main; font-style: normal; }
271
- styles. fontFamily = 'KaTeX_Main' ;
272
- styles. fontStyle = KatexSpanFontStyle .normal;
274
+ fontFamily = 'KaTeX_Main' ;
275
+ fontStyle = KatexSpanFontStyle .normal;
273
276
274
277
// TODO handle skipped class declarations between .mainrm and
275
278
// .sizing .
@@ -295,20 +298,20 @@ class _KatexParser {
295
298
// These indexes start at 1.
296
299
if (resetSizeIdx > sizes.length) throw KatexHtmlParseError ();
297
300
if (sizeIdx > sizes.length) throw KatexHtmlParseError ();
298
- styles. fontSizeEm = sizes[sizeIdx - 1 ] / sizes[resetSizeIdx - 1 ];
301
+ fontSizeEm = sizes[sizeIdx - 1 ] / sizes[resetSizeIdx - 1 ];
299
302
300
303
case 'delimsizing' :
301
304
// .delimsizing { ... }
302
305
if (index + 1 > spanClasses.length) throw KatexHtmlParseError ();
303
306
switch (spanClasses[index++ ]) {
304
307
case 'size1' :
305
- styles. fontFamily = 'KaTeX_Size1' ;
308
+ fontFamily = 'KaTeX_Size1' ;
306
309
case 'size2' :
307
- styles. fontFamily = 'KaTeX_Size2' ;
310
+ fontFamily = 'KaTeX_Size2' ;
308
311
case 'size3' :
309
- styles. fontFamily = 'KaTeX_Size3' ;
312
+ fontFamily = 'KaTeX_Size3' ;
310
313
case 'size4' :
311
- styles. fontFamily = 'KaTeX_Size4' ;
314
+ fontFamily = 'KaTeX_Size4' ;
312
315
313
316
case 'mult' :
314
317
// TODO handle nested spans with `.delim-size{1,4}` class.
@@ -325,9 +328,9 @@ class _KatexParser {
325
328
if (index + 1 > spanClasses.length) throw KatexHtmlParseError ();
326
329
switch (spanClasses[index++ ]) {
327
330
case 'small-op' :
328
- styles. fontFamily = 'KaTeX_Size1' ;
331
+ fontFamily = 'KaTeX_Size1' ;
329
332
case 'large-op' :
330
- styles. fontFamily = 'KaTeX_Size2' ;
333
+ fontFamily = 'KaTeX_Size2' ;
331
334
default :
332
335
throw KatexHtmlParseError ();
333
336
}
@@ -344,6 +347,13 @@ class _KatexParser {
344
347
_logError ('KaTeX: Unsupported CSS class: $spanClass ' );
345
348
}
346
349
}
350
+ final styles = KatexSpanStyles (
351
+ fontFamily: fontFamily,
352
+ fontSizeEm: fontSizeEm,
353
+ fontWeight: fontWeight,
354
+ fontStyle: fontStyle,
355
+ textAlign: textAlign,
356
+ );
347
357
348
358
String ? text;
349
359
List <KatexNode >? spans;
@@ -376,14 +386,15 @@ enum KatexSpanTextAlign {
376
386
right,
377
387
}
378
388
389
+ @immutable
379
390
class KatexSpanStyles {
380
- String ? fontFamily;
381
- double ? fontSizeEm;
382
- KatexSpanFontWeight ? fontWeight;
383
- KatexSpanFontStyle ? fontStyle;
384
- KatexSpanTextAlign ? textAlign;
391
+ final String ? fontFamily;
392
+ final double ? fontSizeEm;
393
+ final KatexSpanFontWeight ? fontWeight;
394
+ final KatexSpanFontStyle ? fontStyle;
395
+ final KatexSpanTextAlign ? textAlign;
385
396
386
- KatexSpanStyles ({
397
+ const KatexSpanStyles ({
387
398
this .fontFamily,
388
399
this .fontSizeEm,
389
400
this .fontWeight,
0 commit comments