Skip to content

Commit 8310d37

Browse files
committed
content: Make TeX in link spans link-colored
Fixes #1823.
1 parent 61a118b commit 8310d37

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/widgets/katex.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:flutter/rendering.dart';
66

77
import '../model/content.dart';
88
import '../model/katex.dart';
9-
import 'content.dart';
109

1110
/// Creates a base text style for rendering KaTeX content.
1211
///
@@ -16,17 +15,14 @@ import 'content.dart';
1615
/// https://github.com/KaTeX/KaTeX/blob/613c3da8/src/styles/katex.scss#L13-L15
1716
///
1817
/// Requires the [ambientStyle.fontSize] to be non-null.
19-
TextStyle mkBaseKatexTextStyle(TextStyle ambientStyle, Color baseColor) {
18+
TextStyle mkBaseKatexTextStyle(TextStyle ambientStyle) {
2019
return ambientStyle.copyWith(
2120
////// Overrides of our own styles:
2221
2322
// Bold formatting is removed below by setting FontWeight.normal…
2423
// Just for completeness, remove "wght", but it wouldn't do anything anyway
2524
// since KaTeX_Main is not a variable-weight font.
2625
fontVariations: [],
27-
// Remove link color, but
28-
// TODO(#1823) do we want to do that? Web doesn't.
29-
color: baseColor,
3026
// Italic is removed below.
3127

3228
// Strikethrough is removed below, which affects formatting of rendered
@@ -68,8 +64,7 @@ class KatexWidget extends StatelessWidget {
6864
return Directionality(
6965
textDirection: TextDirection.ltr,
7066
child: DefaultTextStyle(
71-
style: mkBaseKatexTextStyle(ambientTextStyle,
72-
ContentTheme.of(context).textStylePlainParagraph.color!),
67+
style: mkBaseKatexTextStyle(ambientTextStyle),
7368
child: widget));
7469
}
7570
}

test/widgets/content_test.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,13 +997,22 @@ void main() {
997997

998998
testContentSmoke(ContentExample.mathInline);
999999

1000+
final mathInlineHtml = '<span class="katex">'
1001+
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
1002+
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
1003+
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span>';
1004+
1005+
testWidgets('is link-colored in link span', (tester) async {
1006+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/1823
1007+
await prepareContent(tester,
1008+
plainContent('<p><a href="https://example/">$mathInlineHtml</a></p>'));
1009+
final style = mergedStyleOf(tester, 'λ');
1010+
check(style!.color).equals(const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor());
1011+
});
1012+
10001013
testWidgets('maintains font-size ratio with surrounding text', (tester) async {
1001-
const html = '<span class="katex">'
1002-
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
1003-
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
1004-
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span>';
10051014
await checkFontSizeRatio(tester,
1006-
targetHtml: html,
1015+
targetHtml: mathInlineHtml,
10071016
targetFontSizeFinder: (rootSpan) {
10081017
late final double result;
10091018
rootSpan.visitChildren((span) {

0 commit comments

Comments
 (0)