Skip to content

Commit da5c1f7

Browse files
rajveermalviyagnprice
authored andcommitted
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 6459af6 commit da5c1f7

File tree

7 files changed

+60
-79
lines changed

7 files changed

+60
-79
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: 31 additions & 5 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';
@@ -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+
null, // r"$$ \lambda $$" (hypothetical server variation)
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
@@ -25,7 +25,6 @@ import '../example_data.dart' as eg;
2525
import '../flutter_checks.dart';
2626
import '../model/binding.dart';
2727
import '../model/content_test.dart';
28-
import '../model/store_checks.dart';
2928
import '../model/test_store.dart';
3029
import '../test_images.dart';
3130
import '../test_navigation.dart';
@@ -566,22 +565,13 @@ void main() {
566565

567566
testContentSmoke(ContentExample.mathBlock);
568567

569-
testWidgets('displays KaTeX content; experimental flag enabled', (tester) async {
570-
addTearDown(testBinding.reset);
571-
final globalSettings = testBinding.globalStore.settings;
572-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
573-
check(globalSettings).getBool(BoolGlobalSetting.renderKatex).isTrue();
574-
568+
testWidgets('displays KaTeX content', (tester) async {
575569
await prepareContent(tester, plainContent(ContentExample.mathBlock.html));
576570
tester.widget(find.text('λ', findRichText: true));
577571
});
578572

579-
testWidgets('displays KaTeX source; experimental flag disabled', (tester) async {
580-
addTearDown(testBinding.reset);
581-
final globalSettings = testBinding.globalStore.settings;
582-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);
583-
584-
await prepareContent(tester, plainContent(ContentExample.mathBlock.html));
573+
testWidgets('fallback to displaying KaTeX source if unsupported KaTeX HTML', (tester) async {
574+
await prepareContent(tester, plainContent(ContentExample.mathBlockUnknown.html));
585575
tester.widget(find.text(r'\lambda', findRichText: true));
586576
});
587577
});
@@ -1000,11 +990,6 @@ void main() {
1000990
testContentSmoke(ContentExample.mathInline);
1001991

1002992
testWidgets('maintains font-size ratio with surrounding text', (tester) async {
1003-
addTearDown(testBinding.reset);
1004-
final globalSettings = testBinding.globalStore.settings;
1005-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
1006-
check(globalSettings.getBool(BoolGlobalSetting.renderKatex)).isTrue();
1007-
1008993
const html = '<span class="katex">'
1009994
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
1010995
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
@@ -1025,37 +1010,27 @@ void main() {
10251010
});
10261011
});
10271012

1028-
testWidgets('maintains font-size ratio with surrounding text, when showing TeX source', (tester) async {
1029-
addTearDown(testBinding.reset);
1030-
final globalSettings = testBinding.globalStore.settings;
1031-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);
1032-
1033-
const html = '<span class="katex">'
1013+
testWidgets('maintains font-size ratio with surrounding text, when falling back to TeX source', (tester) async {
1014+
const unsupportedHtml = '<span class="katex">'
10341015
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
10351016
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
1036-
'<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>';
1017+
'<span class="katex-html" aria-hidden="true">'
1018+
'<span class="base unknown">' // Server doesn't generate this 'unknown' class.
1019+
'<span class="strut" style="height:0.6944em;"></span>'
1020+
'<span class="mord mathnormal">λ</span></span></span></span>';
10371021
await checkFontSizeRatio(tester,
1038-
targetHtml: html,
1022+
targetHtml: unsupportedHtml,
10391023
targetFontSizeFinder: mkTargetFontSizeFinderFromPattern(r'\lambda'));
10401024
});
10411025

1042-
testWidgets('displays KaTeX content; experimental flag enabled', (tester) async {
1043-
addTearDown(testBinding.reset);
1044-
final globalSettings = testBinding.globalStore.settings;
1045-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
1046-
check(globalSettings.getBool(BoolGlobalSetting.renderKatex)).isTrue();
1047-
1026+
testWidgets('displays KaTeX content', (tester) async {
10481027
await prepareContent(tester, plainContent(ContentExample.mathInline.html));
10491028
tester.widget(find.text('λ', findRichText: true));
10501029
});
10511030

1052-
testWidgets('displays KaTeX source; experimental flag disabled', (tester) async {
1053-
addTearDown(testBinding.reset);
1054-
final globalSettings = testBinding.globalStore.settings;
1055-
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);
1056-
1057-
await prepareContent(tester, plainContent(ContentExample.mathInline.html));
1058-
tester.widget(find.text(r'\lambda', findRichText: true));
1031+
testWidgets('fallback to displaying KaTeX source if unsupported KaTeX HTML', (tester) async {
1032+
await prepareContent(tester, plainContent(ContentExample.mathInlineUnknown.html));
1033+
tester.widget(find.text(r'\lambda'));
10591034
});
10601035
});
10611036

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)