Skip to content

Commit 8ad5c0d

Browse files
katex: Remove renderKaTex experimental flag
This flag has been enabled since v0.0.29 (beta) release, and we don't plan to disable it. So remove the flag completely, simplifying related code. Fixes: #1728
1 parent 8437134 commit 8ad5c0d

File tree

7 files changed

+61
-80
lines changed

7 files changed

+61
-80
lines changed

lib/model/katex.dart

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,27 @@ MathParserResult? parseMath(dom.Element element, { required bool block }) {
116116
// content parsing stage here, thus the `!` here.
117117
final globalStore = ZulipBinding.instance.getGlobalStoreSync()!;
118118
final globalSettings = globalStore.settings;
119-
final flagRenderKatex =
120-
globalSettings.getBool(BoolGlobalSetting.renderKatex);
121119
final flagForceRenderKatex =
122120
globalSettings.getBool(BoolGlobalSetting.forceRenderKatex);
123121

124122
KatexParserHardFailReason? hardFailReason;
125123
KatexParserSoftFailReason? softFailReason;
126124
List<KatexNode>? nodes;
127-
if (flagRenderKatex) {
128-
final parser = _KatexParser();
129-
try {
130-
nodes = parser.parseKatexHtml(katexHtmlElement);
131-
} on _KatexHtmlParseError catch (e, st) {
132-
assert(debugLog('$e\n$st'));
133-
hardFailReason = KatexParserHardFailReason(
134-
message: e.message,
135-
stackTrace: st);
136-
}
125+
final parser = _KatexParser();
126+
try {
127+
nodes = parser.parseKatexHtml(katexHtmlElement);
128+
} on _KatexHtmlParseError catch (e, st) {
129+
assert(debugLog('$e\n$st'));
130+
hardFailReason = KatexParserHardFailReason(
131+
message: e.message,
132+
stackTrace: st);
133+
}
137134

138-
if (parser.hasError && !flagForceRenderKatex) {
139-
nodes = null;
140-
softFailReason = KatexParserSoftFailReason(
141-
unsupportedCssClasses: parser.unsupportedCssClasses,
142-
unsupportedInlineCssProperties: parser.unsupportedInlineCssProperties);
143-
}
135+
if (parser.hasError && !flagForceRenderKatex) {
136+
nodes = null;
137+
softFailReason = KatexParserSoftFailReason(
138+
unsupportedCssClasses: parser.unsupportedCssClasses,
139+
unsupportedInlineCssProperties: parser.unsupportedInlineCssProperties);
144140
}
145141

146142
return MathParserResult(

lib/model/settings.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,14 @@ enum BoolGlobalSetting {
177177
/// welcome dialog for upgrading from the legacy app.
178178
upgradeWelcomeDialogShown(GlobalSettingType.internal, false),
179179

180-
/// An experimental flag to toggle rendering KaTeX content in messages.
181-
renderKatex(GlobalSettingType.experimentalFeatureFlag, true),
182-
183180
/// An experimental flag to enable rendering KaTeX even when some
184181
/// errors are encountered.
185182
forceRenderKatex(GlobalSettingType.experimentalFeatureFlag, false),
186183

187184
// Former settings which might exist in the database,
188185
// whose names should therefore not be reused:
189186
// openFirstUnread // v0.0.30
187+
// renderKatex // v0.0.29 - v30.0.261
190188
;
191189

192190
const BoolGlobalSetting(this.type, this.default_);

test/model/content_test.dart

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:stack_trace/stack_trace.dart';
66
import 'package:test/scaffolding.dart';
77
import 'package:zulip/model/code_block.dart';
88
import 'package:zulip/model/content.dart';
9-
import 'package:zulip/model/settings.dart';
109
import 'package:zulip/model/katex.dart';
1110

1211
import 'binding.dart';
@@ -511,7 +510,7 @@ class ContentExample {
511510

512511
static final mathInline = ContentExample.inline(
513512
'inline math',
514-
r"$$ \lambda $$",
513+
null, // r"$$ \lambda $$" (hypothetical server variation)
515514
expectedText: r'λ',
516515
'<p><span class="katex">'
517516
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
@@ -528,6 +527,20 @@ class ContentExample {
528527
]),
529528
]));
530529

530+
// A test message to test the fallback behaviour of KaTeX implementation.
531+
static final mathInlineUnknown = ContentExample.inline(
532+
'inline math',
533+
r"$$ \lambda $$",
534+
expectedText: r'\lambda',
535+
'<p><span class="katex">'
536+
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
537+
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
538+
'<span class="katex-html" aria-hidden="true">'
539+
'<span class="base unknown">' // Server doesn't generate this 'unknown' class.
540+
'<span class="strut" style="height:0.6944em;"></span>'
541+
'<span class="mord mathnormal">λ</span></span></span></span></p>',
542+
MathInlineNode(texSource: r'\lambda', nodes: null));
543+
531544
static const mathBlock = ContentExample(
532545
'math block',
533546
"```math\n\\lambda\n```",
@@ -547,6 +560,20 @@ class ContentExample {
547560
]),
548561
])]);
549562

563+
// A test message to test the fallback behaviour of KaTeX implementation.
564+
static const mathBlockUnknown = ContentExample(
565+
'math block unknown, fallback to TeX source',
566+
null, // r"```math\n\lambda\n```" (hypothetical server variation)
567+
expectedText: r'\lambda',
568+
'<p><span class="katex-display"><span class="katex">'
569+
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>λ</mi></mrow>'
570+
'<annotation encoding="application/x-tex">\\lambda</annotation></semantics></math></span>'
571+
'<span class="katex-html" aria-hidden="true">'
572+
'<span class="base unknown">' // Server doesn't generate this 'unknown' class.
573+
'<span class="strut" style="height:0.6944em;"></span>'
574+
'<span class="mord mathnormal">λ</span></span></span></span></span></p>',
575+
[MathBlockNode(texSource: r'\lambda', nodes: null)]);
576+
550577
static const mathBlocksMultipleInParagraph = ContentExample(
551578
'math blocks, multiple in paragraph',
552579
'```math\na\n\nb\n```',
@@ -1484,10 +1511,6 @@ void main() async {
14841511

14851512
TestZulipBinding.ensureInitialized();
14861513

1487-
// We need this to be able to test the currently experimental KaTeX code.
1488-
await testBinding.globalStore.settings.setBool(
1489-
BoolGlobalSetting.renderKatex, true);
1490-
14911514
//
14921515
// Inline content.
14931516
//
@@ -1599,6 +1622,7 @@ void main() async {
15991622
testParseExample(ContentExample.emojiZulipExtra);
16001623

16011624
testParseExample(ContentExample.mathInline);
1625+
testParseExample(ContentExample.mathInlineUnknown);
16021626

16031627
group('global times', () {
16041628
testParseExample(ContentExample.globalTime);
@@ -1777,6 +1801,8 @@ void main() async {
17771801
// into the context of a Zulip message.
17781802
// For tests going deeper inside KaTeX content, see katex_test.dart.
17791803
testParseExample(ContentExample.mathBlock);
1804+
testParseExample(ContentExample.mathBlockUnknown);
1805+
17801806
testParseExample(ContentExample.mathBlocksMultipleInParagraph);
17811807
testParseExample(ContentExample.mathBlockInQuote);
17821808
testParseExample(ContentExample.mathBlocksMultipleInQuote);

test/model/katex_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:io';
22

3-
import 'package:zulip/model/settings.dart';
43
import 'package:checks/checks.dart';
54
import 'package:stack_trace/stack_trace.dart';
65
import 'package:test_api/scaffolding.dart';
@@ -572,9 +571,6 @@ class KatexExample extends ContentExample {
572571
void main() async {
573572
TestZulipBinding.ensureInitialized();
574573

575-
await testBinding.globalStore.settings.setBool(
576-
BoolGlobalSetting.renderKatex, true);
577-
578574
testParseExample(KatexExample.mathBlockKatexSizing);
579575
testParseExample(KatexExample.mathBlockKatexNestedSizing);
580576
testParseExample(KatexExample.mathBlockKatexDelimSizing);

test/widgets/content_test.dart

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import '../example_data.dart' as eg;
2323
import '../flutter_checks.dart';
2424
import '../model/binding.dart';
2525
import '../model/content_test.dart';
26-
import '../model/store_checks.dart';
2726
import '../model/test_store.dart';
2827
import '../test_images.dart';
2928
import '../test_navigation.dart';
@@ -560,22 +559,13 @@ void main() {
560559

561560
testContentSmoke(ContentExample.mathBlock);
562561

563-
testWidgets('displays KaTeX content; experimental flag enabled', (tester) async {
564-
addTearDown(testBinding.reset);
565-
final globalSettings = testBinding.globalStore.settings;
566-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
567-
check(globalSettings).getBool(BoolGlobalSetting.renderKatex).isTrue();
568-
562+
testWidgets('displays KaTeX content', (tester) async {
569563
await prepareContent(tester, plainContent(ContentExample.mathBlock.html));
570564
tester.widget(find.text('λ', findRichText: true));
571565
});
572566

573-
testWidgets('displays KaTeX source; experimental flag disabled', (tester) async {
574-
addTearDown(testBinding.reset);
575-
final globalSettings = testBinding.globalStore.settings;
576-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);
577-
578-
await prepareContent(tester, plainContent(ContentExample.mathBlock.html));
567+
testWidgets('fallback to displaying KaTeX source if unsupported KaTeX HTML', (tester) async {
568+
await prepareContent(tester, plainContent(ContentExample.mathBlockUnknown.html));
579569
tester.widget(find.text(r'\lambda', findRichText: true));
580570
});
581571
});
@@ -992,11 +982,6 @@ void main() {
992982
testContentSmoke(ContentExample.mathInline);
993983

994984
testWidgets('maintains font-size ratio with surrounding text', (tester) async {
995-
addTearDown(testBinding.reset);
996-
final globalSettings = testBinding.globalStore.settings;
997-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
998-
check(globalSettings.getBool(BoolGlobalSetting.renderKatex)).isTrue();
999-
1000985
const html = '<span class="katex">'
1001986
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
1002987
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
@@ -1017,37 +1002,27 @@ void main() {
10171002
});
10181003
});
10191004

1020-
testWidgets('maintains font-size ratio with surrounding text, when showing TeX source', (tester) async {
1021-
addTearDown(testBinding.reset);
1022-
final globalSettings = testBinding.globalStore.settings;
1023-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);
1024-
1025-
const html = '<span class="katex">'
1005+
testWidgets('maintains font-size ratio with surrounding text, when falling back to TeX source', (tester) async {
1006+
const unsupportedHtml = '<span class="katex">'
10261007
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
10271008
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
1028-
'<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>';
1009+
'<span class="katex-html" aria-hidden="true">'
1010+
'<span class="base unknown">' // Server doesn't generate this 'unknown' class.
1011+
'<span class="strut" style="height:0.6944em;"></span>'
1012+
'<span class="mord mathnormal">λ</span></span></span></span>';
10291013
await checkFontSizeRatio(tester,
1030-
targetHtml: html,
1014+
targetHtml: unsupportedHtml,
10311015
targetFontSizeFinder: mkTargetFontSizeFinderFromPattern(r'\lambda'));
10321016
});
10331017

1034-
testWidgets('displays KaTeX content; experimental flag enabled', (tester) async {
1035-
addTearDown(testBinding.reset);
1036-
final globalSettings = testBinding.globalStore.settings;
1037-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
1038-
check(globalSettings.getBool(BoolGlobalSetting.renderKatex)).isTrue();
1039-
1018+
testWidgets('displays KaTeX content', (tester) async {
10401019
await prepareContent(tester, plainContent(ContentExample.mathInline.html));
10411020
tester.widget(find.text('λ', findRichText: true));
10421021
});
10431022

1044-
testWidgets('displays KaTeX source; experimental flag disabled', (tester) async {
1045-
addTearDown(testBinding.reset);
1046-
final globalSettings = testBinding.globalStore.settings;
1047-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);
1048-
1049-
await prepareContent(tester, plainContent(ContentExample.mathInline.html));
1050-
tester.widget(find.text(r'\lambda', findRichText: true));
1023+
testWidgets('fallback to displaying KaTeX source if unsupported KaTeX HTML', (tester) async {
1024+
await prepareContent(tester, plainContent(ContentExample.mathInlineUnknown.html));
1025+
tester.widget(find.text(r'\lambda'));
10511026
});
10521027
});
10531028

test/widgets/katex_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import 'package:checks/checks.dart';
22
import 'package:flutter/services.dart';
33
import 'package:flutter_checks/flutter_checks.dart';
44
import 'package:flutter_test/flutter_test.dart';
5-
import 'package:zulip/model/settings.dart';
65
import 'package:zulip/widgets/katex.dart';
76

87
import '../model/binding.dart';
98
import '../model/katex_test.dart';
10-
import '../model/store_checks.dart';
119
import 'content_test.dart';
1210

1311
void main() {
@@ -81,11 +79,6 @@ void main() {
8179
testWidgets(testCase.$1.description, (tester) async {
8280
await _loadKatexFonts();
8381

84-
addTearDown(testBinding.reset);
85-
final globalSettings = testBinding.globalStore.settings;
86-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
87-
check(globalSettings).getBool(BoolGlobalSetting.renderKatex).isTrue();
88-
8982
await prepareContent(tester, plainContent(testCase.$1.html));
9083

9184
final baseRect = tester.getRect(find.byType(KatexWidget));

tools/content/unimplemented_katex_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ import 'package:collection/collection.dart';
1010
import 'package:flutter/foundation.dart';
1111
import 'package:flutter_test/flutter_test.dart';
1212
import 'package:zulip/model/content.dart';
13-
import 'package:zulip/model/settings.dart';
1413

1514
import '../../test/model/binding.dart';
1615
import 'model.dart';
1716

1817
void main() async {
1918
TestZulipBinding.ensureInitialized();
20-
await testBinding.globalStore.settings.setBool(
21-
BoolGlobalSetting.renderKatex, true);
2219

2320
Future<void> checkForKatexFailuresInFile(File file) async {
2421
int totalMessageCount = 0;

0 commit comments

Comments
 (0)