Skip to content

Commit 51999fa

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 9cc6700 commit 51999fa

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/widgets/katex.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,28 @@ 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(design) do we want to do that?
29+
color: baseColor,
30+
// italic and strikethrough are removed below, but
31+
// TODO(design) do we want to remove a strikethrough?
32+
33+
////// From the .katex class in katex.scss:
34+
1935
fontSize: style.fontSize! * 1.21,
2036
fontFamily: 'KaTeX_Main',
2137
height: 1.2,
@@ -45,8 +61,8 @@ class KatexWidget extends StatelessWidget {
4561
return Directionality(
4662
textDirection: TextDirection.ltr,
4763
child: DefaultTextStyle(
48-
style: mkBaseKatexTextStyle(textStyle).copyWith(
49-
color: ContentTheme.of(context).textStylePlainParagraph.color),
64+
style: mkBaseKatexTextStyle(textStyle,
65+
ContentTheme.of(context).textStylePlainParagraph.color!),
5066
child: widget));
5167
}
5268
}

0 commit comments

Comments
 (0)