Skip to content

Commit

Permalink
content [nfc]: Move _kCodeBlockStyle to CodeBlockTextStyles
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe committed Jun 6, 2024
1 parent 708d79f commit 88c2755
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib/widgets/code_block.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

import '../model/code_block.dart';
import 'content.dart';
import 'text.dart';

/// [TextStyle]s used to render code blocks.
Expand All @@ -11,6 +12,11 @@ class CodeBlockTextStyles {
factory CodeBlockTextStyles(BuildContext context) {
final bold = weightVariableTextStyle(context, wght: 700);
return CodeBlockTextStyles._(
plain: kMonospaceTextStyle
.merge(const TextStyle(
fontSize: 0.825 * kBaseFontSize,
height: 1.4)),

// .hll { background-color: hsl(60deg 100% 90%); }
hll: TextStyle(backgroundColor: const HSLColor.fromAHSL(1, 60, 1, 0.90).toColor()),

Expand Down Expand Up @@ -204,6 +210,7 @@ class CodeBlockTextStyles {
}

CodeBlockTextStyles._({
required this.plain,
required TextStyle hll,
required TextStyle c,
required TextStyle err,
Expand Down Expand Up @@ -330,6 +337,8 @@ class CodeBlockTextStyles {
_vi = vi,
_il = il;

final TextStyle plain;

final TextStyle _hll;
final TextStyle _c;
final TextStyle _err;
Expand Down Expand Up @@ -471,6 +480,7 @@ class CodeBlockTextStyles {
if (identical(this, other)) return this;

return CodeBlockTextStyles._(
plain: TextStyle.lerp(plain, other?.plain, t)!,
hll: TextStyle.lerp(_hll, other?._hll, t)!,
c: TextStyle.lerp(_c, other?._c, t)!,
err: TextStyle.lerp(_err, other?._err, t)!,
Expand Down
10 changes: 2 additions & 8 deletions lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ class CodeBlock extends StatelessWidget {

InlineSpan _buildNodes(List<CodeBlockSpanNode> nodes, {required CodeBlockTextStyles styles}) {
return TextSpan(
style: _kCodeBlockStyle,
style: styles.plain,
children: nodes.map((n) => _buildNode(n, styles: styles)).toList(growable: false));
}

Expand Down Expand Up @@ -651,7 +651,7 @@ class MathBlock extends StatelessWidget {
return _CodeBlockContainer(
borderColor: _borderColor,
child: Text.rich(TextSpan(
style: _kCodeBlockStyle,
style: ContentTheme.of(context).codeBlockTextStyles.plain,
children: [TextSpan(text: node.texSource)])));
}
}
Expand Down Expand Up @@ -938,12 +938,6 @@ final _kInlineCodeStyle = kMonospaceTextStyle
.merge(TextStyle(
backgroundColor: const HSLColor.fromAHSL(0.04, 0, 0, 0).toColor()));

final _kCodeBlockStyle = kMonospaceTextStyle
.merge(const TextStyle(
fontSize: 0.825 * kBaseFontSize,
height: 1.4,
));

// const _kInlineCodeLeftBracket = '⸤';
// const _kInlineCodeRightBracket = '⸣';
// Some alternatives:
Expand Down

0 comments on commit 88c2755

Please sign in to comment.