Skip to content

Commit 3ac0037

Browse files
committed
katex [nfc]: Increment class index at top of loop
This way there's nothing that needs to happen at the bottom of the loop, if any of the cases matched.
1 parent 16ce3e1 commit 3ac0037

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib/model/katex.dart

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ class _KatexParser {
149149
var styles = KatexSpanStyles();
150150
var index = 0;
151151
while (index < spanClasses.length) {
152+
final spanClass = spanClasses[index++];
152153
var classFound = false;
153154

154-
final spanClass = spanClasses[index];
155155
switch (spanClass) {
156156
case 'base':
157157
// .base { ... }
@@ -306,9 +306,9 @@ class _KatexParser {
306306
case 'fontsize-ensurer':
307307
// .sizing,
308308
// .fontsize-ensurer { ... }
309-
if (index + 2 < spanClasses.length) {
310-
final resetSizeClass = spanClasses[index + 1];
311-
final sizeClass = spanClasses[index + 2];
309+
if (index + 1 < spanClasses.length) {
310+
final resetSizeClass = spanClasses[index];
311+
final sizeClass = spanClasses[index + 1];
312312

313313
final resetSizeClassSuffix = _resetSizeClassRegExp.firstMatch(resetSizeClass)?.group(1);
314314
final sizeClassSuffix = _sizeClassRegExp.firstMatch(sizeClass)?.group(1);
@@ -322,7 +322,7 @@ class _KatexParser {
322322
// These indexes start at 1.
323323
if (resetSizeIdx <= sizes.length && sizeIdx <= sizes.length) {
324324
styles.fontSizeEm = sizes[sizeIdx - 1] / sizes[resetSizeIdx - 1];
325-
index += 3;
325+
index += 2;
326326
continue;
327327
}
328328
}
@@ -332,8 +332,8 @@ class _KatexParser {
332332

333333
case 'delimsizing':
334334
// .delimsizing { ... }
335-
if (index + 1 < spanClasses.length) {
336-
final nextClass = spanClasses[index + 1];
335+
if (index < spanClasses.length) {
336+
final nextClass = spanClasses[index];
337337
switch (nextClass) {
338338
case 'size1':
339339
styles.fontFamily = 'KaTeX_Size1';
@@ -351,7 +351,7 @@ class _KatexParser {
351351

352352
if (styles.fontFamily == null) throw KatexHtmlParseError();
353353

354-
index += 2;
354+
index += 1;
355355
continue;
356356
}
357357

@@ -361,8 +361,8 @@ class _KatexParser {
361361

362362
case 'op-symbol':
363363
// .op-symbol { ... }
364-
if (index + 1 < spanClasses.length) {
365-
final nextClass = spanClasses[index + 1];
364+
if (index < spanClasses.length) {
365+
final nextClass = spanClasses[index];
366366
switch (nextClass) {
367367
case 'small-op':
368368
styles.fontFamily = 'KaTeX_Size1';
@@ -371,7 +371,7 @@ class _KatexParser {
371371
}
372372
if (styles.fontFamily == null) throw KatexHtmlParseError();
373373

374-
index += 2;
374+
index += 1;
375375
continue;
376376
}
377377

@@ -389,8 +389,6 @@ class _KatexParser {
389389
}
390390

391391
if (!classFound) _logError('KaTeX: Unsupported CSS class: $spanClass');
392-
393-
index++;
394392
}
395393

396394
String? text;

0 commit comments

Comments
 (0)