Skip to content

Commit 9f0757d

Browse files
committed
katex [nfc]: Consolidate where we cancel out ambient text styles
In the inline-math case, we're about to pass the actual ambient text style, which may have italic, strikethrough, bold, or link formatting. Consolidate the code that overrides each of those, so that it reads as intentional, and add TODOs for overrides that we might not want to keep.
1 parent e12673a commit 9f0757d

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

lib/widgets/katex.dart

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,35 @@ import 'content.dart';
1010

1111
/// Creates a base text style for rendering KaTeX content.
1212
///
13-
/// This applies the CSS styles defined in .katex class in katex.scss :
13+
/// This cancels out some attributes that may be ambient from Zulip content
14+
/// (italic, bold, etc.)
15+
/// and applies the CSS styles defined in .katex class in katex.scss :
1416
/// https://github.com/KaTeX/KaTeX/blob/613c3da8/src/styles/katex.scss#L13-L15
1517
///
1618
/// Requires the [style.fontSize] to be non-null.
17-
TextStyle mkBaseKatexTextStyle(TextStyle style) {
19+
TextStyle mkBaseKatexTextStyle(TextStyle style, Color baseColor) {
1820
return style.copyWith(
21+
////// Overrides of our own styles:
22+
23+
// Bold formatting is removed below by setting FontWeight.normal…
24+
// Just for completeness, remove "wght", but it wouldn't do anything anyway
25+
// since KaTeX_Main is not a variable-weight font.
26+
fontVariations: [],
27+
// Remove link color, but
28+
// TODO(#1823) do we want to do that? Web doesn't.
29+
color: baseColor,
30+
// Italic is removed below.
31+
32+
// Strikethrough is removed below, which affects formatting of rendered
33+
// KatexSpanNodes…but a single strikethrough on the whole KatexWidget will
34+
// be visible as long as it doesn't paint an opaque background. (The line
35+
// "shows through" from an ancestor span.) I think we're happy with this:
36+
// the message author asked for a strikethrough by wrapping the math in ~~,
37+
// but we should render it as one unbroken line, not separate lines on each
38+
// KaTeX span.
39+
40+
////// From the .katex class in katex.scss:
41+
1942
fontSize: style.fontSize! * 1.21,
2043
fontFamily: 'KaTeX_Main',
2144
height: 1.2,
@@ -45,8 +68,8 @@ class KatexWidget extends StatelessWidget {
4568
return Directionality(
4669
textDirection: TextDirection.ltr,
4770
child: DefaultTextStyle(
48-
style: mkBaseKatexTextStyle(textStyle).copyWith(
49-
color: ContentTheme.of(context).textStylePlainParagraph.color),
71+
style: mkBaseKatexTextStyle(textStyle,
72+
ContentTheme.of(context).textStylePlainParagraph.color!),
5073
child: widget));
5174
}
5275
}

0 commit comments

Comments
 (0)