Skip to content

Commit

Permalink
Remove hard-coded colors in Markdown default code theme (#731)
Browse files Browse the repository at this point in the history
Fix #728
  • Loading branch information
FeodorFitsner authored Dec 18, 2022
1 parent cc48859 commit 384bf3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions package/lib/src/controls/highlight_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class HighlightView extends StatelessWidget {
}

static const _rootKey = 'root';
static const _defaultFontColor = Color(0xff000000);
static const _defaultBackgroundColor = Color(0xffffffff);

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

var d = BoxDecoration(
color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor);
color: theme[_rootKey]?.backgroundColor ??
Theme.of(context).colorScheme.surfaceVariant);

if (decoration != null) {
d = d.copyWith(borderRadius: (decoration as BoxDecoration).borderRadius);
Expand Down
7 changes: 4 additions & 3 deletions package/lib/src/controls/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MarkdownControl extends StatelessWidget {
final ws = FletAppServices.of(context).ws;

var value = control.attrString("value", "")!;
var codeTheme = control.attrString("codeTheme", "github")!;
var codeTheme = control.attrString("codeTheme", "")!;
md.ExtensionSet extensionSet = md.ExtensionSet.none;
switch (control.attrString("extensionSet", "")!.toLowerCase()) {
case "commonmark":
Expand Down Expand Up @@ -60,7 +60,8 @@ class MarkdownControl extends StatelessWidget {
imageDirectory: getBaseUri(pageUri!).toString(),
extensionSet: extensionSet,
builders: {
'code': CodeElementBuilder(codeTheme, mdStyleSheet),
'code':
CodeElementBuilder(codeTheme.toLowerCase(), mdStyleSheet),
},
styleSheet: mdStyleSheet,
onTapLink: (String text, String? href, String title) {
Expand Down Expand Up @@ -105,7 +106,7 @@ class CodeElementBuilder extends MarkdownElementBuilder {

// Specify highlight theme
// All available themes are listed in `themes` folder
theme: themeMap[codeTheme] ?? themeMap["github"]!,
theme: themeMap[codeTheme] ?? {},

// Specify padding
padding: mdStyleSheet.codeblockPadding,
Expand Down

0 comments on commit 384bf3e

Please sign in to comment.