Skip to content

Commit fe383b8

Browse files
committed
katex [nfc]: Consolidate logic for computing overall styles of KatexSpanNode
This just pulls these three pieces of closely-related logic next to each other. That will make it easier to refactor them further. This causes one change in the survey script's list of failure reasons: when the `delimcenter` class occurs with an inline `top` property, we now record the unsupported class before reaching the hard fail for the unsupported property. This has no user-visible effect, though, because it can only happen when the expression is going to reach that hard failure either way.
1 parent 73ae269 commit fe383b8

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lib/model/katex.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,6 @@ class _KatexParser {
369369
}
370370
}
371371

372-
final inlineStyles = _parseSpanInlineStyles(element);
373-
if (inlineStyles != null) {
374-
// Currently, we expect `top` to only be inside a vlist, and
375-
// we handle that case separately above.
376-
if (inlineStyles.topEm != null) {
377-
throw _KatexHtmlParseError('unsupported inline CSS property: top');
378-
}
379-
}
380-
381372
// Aggregate the CSS styles that apply, in the same order as the CSS
382373
// classes specified for this span, mimicking the behaviour on web.
383374
//
@@ -621,13 +612,23 @@ class _KatexParser {
621612
_hasError = true;
622613
}
623614
}
624-
final styles = KatexSpanStyles(
615+
final classStyles = KatexSpanStyles(
625616
fontFamily: fontFamily,
626617
fontSizeEm: fontSizeEm,
627618
fontWeight: fontWeight,
628619
fontStyle: fontStyle,
629620
textAlign: textAlign,
630621
);
622+
final inlineStyles = _parseSpanInlineStyles(element);
623+
if (inlineStyles != null) {
624+
// Currently, we expect `top` to only be inside a vlist, and
625+
// we handle that case separately above.
626+
if (inlineStyles.topEm != null) {
627+
throw _KatexHtmlParseError('unsupported inline CSS property: top');
628+
}
629+
}
630+
final styles = inlineStyles == null ? classStyles
631+
: classStyles.merge(inlineStyles);
631632

632633
String? text;
633634
List<KatexNode>? spans;
@@ -639,9 +640,7 @@ class _KatexParser {
639640
if (text == null && spans == null) throw _KatexHtmlParseError();
640641

641642
return KatexSpanNode(
642-
styles: inlineStyles != null
643-
? styles.merge(inlineStyles)
644-
: styles,
643+
styles: styles,
645644
text: text,
646645
nodes: spans,
647646
debugHtmlNode: debugHtmlNode);

0 commit comments

Comments
 (0)