Skip to content

Commit 8d9f89c

Browse files
committed
NOMERGE demo flag: renderKatex
This demonstrates what's involved in introducing a new experimental feature flag.
1 parent 23f41f5 commit 8d9f89c

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

lib/model/settings.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ enum BoolGlobalSetting {
110110
/// (Having one stable value in this enum is also handy for tests.)
111111
placeholderIgnore(GlobalSettingType.placeholder, false),
112112

113+
renderKatex(GlobalSettingType.experimentalFeatureFlag, false),
114+
113115
// Former settings which might exist in the database,
114116
// whose names should therefore not be reused:
115117
// (this list is empty so far)

lib/widgets/content.dart

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import '../model/avatar_url.dart';
1515
import '../model/binding.dart';
1616
import '../model/content.dart';
1717
import '../model/internal_link.dart';
18+
import '../model/settings.dart';
1819
import 'code_block.dart';
1920
import 'dialog.dart';
2021
import 'icons.dart';
@@ -831,11 +832,19 @@ class MathBlock extends StatelessWidget {
831832
@override
832833
Widget build(BuildContext context) {
833834
final contentTheme = ContentTheme.of(context);
834-
return _CodeBlockContainer(
835-
borderColor: contentTheme.colorMathBlockBorder,
836-
child: Text.rich(TextSpan(
837-
style: contentTheme.codeBlockTextStyles.plain,
838-
children: [TextSpan(text: node.texSource)])));
835+
final globalSettings = GlobalStoreWidget.settingsOf(context);
836+
837+
final renderKatex = globalSettings.getBool(BoolGlobalSetting.renderKatex);
838+
if (!renderKatex) {
839+
return _CodeBlockContainer(
840+
borderColor: contentTheme.colorMathBlockBorder,
841+
child: Text.rich(TextSpan(
842+
style: contentTheme.codeBlockTextStyles.plain,
843+
children: [TextSpan(text: node.texSource)])));
844+
}
845+
846+
return Text(style: contentTheme.textStyleError,
847+
'(error: KaTeX unimplemented)'); // TODO(#1408)
839848
}
840849
}
841850

@@ -1147,11 +1156,19 @@ class _InlineContentBuilder {
11471156
child: MessageImageEmoji(node: node));
11481157

11491158
case MathInlineNode():
1150-
return TextSpan(
1151-
style: widget.style
1152-
.merge(ContentTheme.of(_context!).textStyleInlineMath)
1153-
.apply(fontSizeFactor: kInlineCodeFontSizeFactor),
1154-
children: [TextSpan(text: node.texSource)]);
1159+
final contentTheme = ContentTheme.of(_context!);
1160+
final globalSettings = GlobalStoreWidget.settingsOf(_context!);
1161+
final renderKatex = globalSettings.getBool(BoolGlobalSetting.renderKatex);
1162+
if (!renderKatex) {
1163+
return TextSpan(
1164+
style: widget.style
1165+
.merge(ContentTheme.of(_context!).textStyleInlineMath)
1166+
.apply(fontSizeFactor: kInlineCodeFontSizeFactor),
1167+
children: [TextSpan(text: node.texSource)]);
1168+
}
1169+
1170+
return TextSpan(style: contentTheme.textStyleError,
1171+
text: '(error: KaTeX unimplemented)'); // TODO(#1408)
11551172

11561173
case GlobalTimeNode():
11571174
return WidgetSpan(alignment: PlaceholderAlignment.middle,

0 commit comments

Comments
 (0)