Skip to content

Commit b8186a7

Browse files
committed
katex [nfc]: Replace classFound local with a default case
Before this change, all cases of this switch statement either continue the loop, or throw, or set classFound to true. The error therefore gets logged just if none of the cases matched. So we can express the same behavior with a default case.
1 parent b003242 commit b8186a7

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

lib/model/katex.dart

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -150,33 +150,28 @@ class _KatexParser {
150150
var index = 0;
151151
while (index < spanClasses.length) {
152152
final spanClass = spanClasses[index++];
153-
var classFound = false;
154-
155153
switch (spanClass) {
156154
case 'base':
157155
// .base { ... }
158156
// Do nothing, it has properties that don't need special handling.
159-
classFound = true;
157+
break;
160158

161159
case 'strut':
162160
// .strut { ... }
163161
// Do nothing, it has properties that don't need special handling.
164-
classFound = true;
162+
break;
165163

166164
case 'textbf':
167165
// .textbf { font-weight: bold; }
168166
styles.fontWeight = KatexSpanFontWeight.bold;
169-
classFound = true;
170167

171168
case 'textit':
172169
// .textit { font-style: italic; }
173170
styles.fontStyle = KatexSpanFontStyle.italic;
174-
classFound = true;
175171

176172
case 'textrm':
177173
// .textrm { font-family: KaTeX_Main; }
178174
styles.fontFamily = 'KaTeX_Main';
179-
classFound = true;
180175

181176
// case 'textsf':
182177
// // .textsf { font-family: KaTeX_SansSerif; }
@@ -186,96 +181,81 @@ class _KatexParser {
186181
case 'texttt':
187182
// .texttt { font-family: KaTeX_Typewriter; }
188183
styles.fontFamily = 'KaTeX_Typewriter';
189-
classFound = true;
190184

191185
case 'mathnormal':
192186
// .mathnormal { font-family: KaTeX_Math; font-style: italic; }
193187
styles.fontFamily = 'KaTeX_Math';
194188
styles.fontStyle = KatexSpanFontStyle.italic;
195-
classFound = true;
196189

197190
case 'mathit':
198191
// .mathit { font-family: KaTeX_Main; font-style: italic; }
199192
styles.fontFamily = 'KaTeX_Main';
200193
styles.fontStyle = KatexSpanFontStyle.italic;
201-
classFound = true;
202194

203195
case 'mathrm':
204196
// .mathrm { font-style: normal; }
205197
styles.fontStyle = KatexSpanFontStyle.normal;
206-
classFound = true;
207198

208199
case 'mathbf':
209200
// .mathbf { font-family: KaTeX_Main; font-weight: bold; }
210201
styles.fontFamily = 'KaTeX_Main';
211202
styles.fontWeight = KatexSpanFontWeight.bold;
212-
classFound = true;
213203

214204
case 'boldsymbol':
215205
// .boldsymbol { font-family: KaTeX_Math; font-weight: bold; font-style: italic; }
216206
styles.fontFamily = 'KaTeX_Math';
217207
styles.fontWeight = KatexSpanFontWeight.bold;
218208
styles.fontStyle = KatexSpanFontStyle.italic;
219-
classFound = true;
220209

221210
case 'amsrm':
222211
// .amsrm { font-family: KaTeX_AMS; }
223212
styles.fontFamily = 'KaTeX_AMS';
224-
classFound = true;
225213

226214
case 'mathbb':
227215
case 'textbb':
228216
// .mathbb,
229217
// .textbb { font-family: KaTeX_AMS; }
230218
styles.fontFamily = 'KaTeX_AMS';
231-
classFound = true;
232219

233220
case 'mathcal':
234221
// .mathcal { font-family: KaTeX_Caligraphic; }
235222
styles.fontFamily = 'KaTeX_Caligraphic';
236-
classFound = true;
237223

238224
case 'mathfrak':
239225
case 'textfrak':
240226
// .mathfrak,
241227
// .textfrak { font-family: KaTeX_Fraktur; }
242228
styles.fontFamily = 'KaTeX_Fraktur';
243-
classFound = true;
244229

245230
case 'mathboldfrak':
246231
case 'textboldfrak':
247232
// .mathboldfrak,
248233
// .textboldfrak { font-family: KaTeX_Fraktur; font-weight: bold; }
249234
styles.fontFamily = 'KaTeX_Fraktur';
250235
styles.fontWeight = KatexSpanFontWeight.bold;
251-
classFound = true;
252236

253237
case 'mathtt':
254238
// .mathtt { font-family: KaTeX_Typewriter; }
255239
styles.fontFamily = 'KaTeX_Typewriter';
256-
classFound = true;
257240

258241
case 'mathscr':
259242
case 'textscr':
260243
// .mathscr,
261244
// .textscr { font-family: KaTeX_Script; }
262245
styles.fontFamily = 'KaTeX_Script';
263-
classFound = true;
264246

265247
case 'mathsf':
266248
case 'textsf':
267249
// .mathsf,
268250
// .textsf { font-family: KaTeX_SansSerif; }
269251
styles.fontFamily = 'KaTeX_SansSerif';
270-
classFound = true;
271252

272253
case 'mathboldsf':
273254
case 'textboldsf':
274255
// .mathboldsf,
275256
// .textboldsf { font-family: KaTeX_SansSerif; font-weight: bold; }
276257
styles.fontFamily = 'KaTeX_SansSerif';
277258
styles.fontWeight = KatexSpanFontWeight.bold;
278-
classFound = true;
279259

280260
case 'mathsfit':
281261
case 'mathitsf':
@@ -285,13 +265,11 @@ class _KatexParser {
285265
// .textitsf { font-family: KaTeX_SansSerif; font-style: italic; }
286266
styles.fontFamily = 'KaTeX_SansSerif';
287267
styles.fontStyle = KatexSpanFontStyle.italic;
288-
classFound = true;
289268

290269
case 'mainrm':
291270
// .mainrm { font-family: KaTeX_Main; font-style: normal; }
292271
styles.fontFamily = 'KaTeX_Main';
293272
styles.fontStyle = KatexSpanFontStyle.normal;
294-
classFound = true;
295273

296274
// TODO handle skipped class declarations between .mainrm and
297275
// .sizing .
@@ -377,10 +355,11 @@ class _KatexParser {
377355
case 'mopen':
378356
// Ignore these classes because they don't have a CSS definition
379357
// in katex.scss, but we encounter them in the generated HTML.
380-
classFound = true;
381-
}
358+
break;
382359

383-
if (!classFound) _logError('KaTeX: Unsupported CSS class: $spanClass');
360+
default:
361+
_logError('KaTeX: Unsupported CSS class: $spanClass');
362+
}
384363
}
385364

386365
String? text;

0 commit comments

Comments
 (0)