Skip to content

Commit 384bf3e

Browse files
Remove hard-coded colors in Markdown default code theme (#731)
Fix #728
1 parent cc48859 commit 384bf3e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

package/lib/src/controls/highlight_view.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class HighlightView extends StatelessWidget {
7474
}
7575

7676
static const _rootKey = 'root';
77-
static const _defaultFontColor = Color(0xff000000);
78-
static const _defaultBackgroundColor = Color(0xffffffff);
7977

8078
// TODO: dart:io is not available at web platform currently
8179
// See: https://github.com/flutter/flutter/issues/39998
@@ -86,14 +84,16 @@ class HighlightView extends StatelessWidget {
8684
Widget build(BuildContext context) {
8785
var style = TextStyle(
8886
fontFamily: _defaultFontFamily,
89-
color: theme[_rootKey]?.color ?? _defaultFontColor,
87+
color: theme[_rootKey]?.color ??
88+
Theme.of(context).colorScheme.onSurfaceVariant,
9089
);
9190
if (textStyle != null) {
9291
style = style.merge(textStyle);
9392
}
9493

9594
var d = BoxDecoration(
96-
color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor);
95+
color: theme[_rootKey]?.backgroundColor ??
96+
Theme.of(context).colorScheme.surfaceVariant);
9797

9898
if (decoration != null) {
9999
d = d.copyWith(borderRadius: (decoration as BoxDecoration).borderRadius);

package/lib/src/controls/markdown.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MarkdownControl extends StatelessWidget {
2626
final ws = FletAppServices.of(context).ws;
2727

2828
var value = control.attrString("value", "")!;
29-
var codeTheme = control.attrString("codeTheme", "github")!;
29+
var codeTheme = control.attrString("codeTheme", "")!;
3030
md.ExtensionSet extensionSet = md.ExtensionSet.none;
3131
switch (control.attrString("extensionSet", "")!.toLowerCase()) {
3232
case "commonmark":
@@ -60,7 +60,8 @@ class MarkdownControl extends StatelessWidget {
6060
imageDirectory: getBaseUri(pageUri!).toString(),
6161
extensionSet: extensionSet,
6262
builders: {
63-
'code': CodeElementBuilder(codeTheme, mdStyleSheet),
63+
'code':
64+
CodeElementBuilder(codeTheme.toLowerCase(), mdStyleSheet),
6465
},
6566
styleSheet: mdStyleSheet,
6667
onTapLink: (String text, String? href, String title) {
@@ -105,7 +106,7 @@ class CodeElementBuilder extends MarkdownElementBuilder {
105106

106107
// Specify highlight theme
107108
// All available themes are listed in `themes` folder
108-
theme: themeMap[codeTheme] ?? themeMap["github"]!,
109+
theme: themeMap[codeTheme] ?? {},
109110

110111
// Specify padding
111112
padding: mdStyleSheet.codeblockPadding,

0 commit comments

Comments
 (0)