Skip to content

Commit 4cac4de

Browse files
committed
content [nfc]: Move _kCodeBlockStyle to CodeBlockTextStyles
1 parent 838abd5 commit 4cac4de

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/widgets/code_block.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
import '../model/code_block.dart';
4+
import 'content.dart';
45
import 'text.dart';
56

67
/// [TextStyle]s used to render code blocks.
@@ -11,6 +12,11 @@ class CodeBlockTextStyles {
1112
factory CodeBlockTextStyles(BuildContext context) {
1213
final bold = weightVariableTextStyle(context, wght: 700);
1314
return CodeBlockTextStyles._(
15+
plain: kMonospaceTextStyle
16+
.merge(const TextStyle(
17+
fontSize: 0.825 * kBaseFontSize,
18+
height: 1.4)),
19+
1420
// .hll { background-color: hsl(60deg 100% 90%); }
1521
hll: TextStyle(backgroundColor: const HSLColor.fromAHSL(1, 60, 1, 0.90).toColor()),
1622

@@ -204,6 +210,7 @@ class CodeBlockTextStyles {
204210
}
205211

206212
CodeBlockTextStyles._({
213+
required this.plain,
207214
required TextStyle hll,
208215
required TextStyle c,
209216
required TextStyle err,
@@ -330,6 +337,9 @@ class CodeBlockTextStyles {
330337
_vi = vi,
331338
_il = il;
332339

340+
/// The baseline style that the [forSpan] styles get applied on top of.
341+
final TextStyle plain;
342+
333343
final TextStyle _hll;
334344
final TextStyle _c;
335345
final TextStyle _err;
@@ -471,6 +481,7 @@ class CodeBlockTextStyles {
471481
if (identical(this, other)) return this;
472482

473483
return CodeBlockTextStyles._(
484+
plain: TextStyle.lerp(plain, other?.plain, t)!,
474485
hll: TextStyle.lerp(_hll, other?._hll, t)!,
475486
c: TextStyle.lerp(_c, other?._c, t)!,
476487
err: TextStyle.lerp(_err, other?._err, t)!,

lib/widgets/content.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class CodeBlock extends StatelessWidget {
590590
return _CodeBlockContainer(
591591
borderColor: Colors.transparent,
592592
child: Text.rich(TextSpan(
593-
style: _kCodeBlockStyle,
593+
style: styles.plain,
594594
children: node.spans
595595
.map((node) => TextSpan(style: styles.forSpan(node.type), text: node.text))
596596
.toList(growable: false))));
@@ -659,7 +659,7 @@ class MathBlock extends StatelessWidget {
659659
return _CodeBlockContainer(
660660
borderColor: _borderColor,
661661
child: Text.rich(TextSpan(
662-
style: _kCodeBlockStyle,
662+
style: ContentTheme.of(context).codeBlockTextStyles.plain,
663663
children: [TextSpan(text: node.texSource)])));
664664
}
665665
}
@@ -946,12 +946,6 @@ final _kInlineCodeStyle = kMonospaceTextStyle
946946
.merge(TextStyle(
947947
backgroundColor: const HSLColor.fromAHSL(0.04, 0, 0, 0).toColor()));
948948

949-
final _kCodeBlockStyle = kMonospaceTextStyle
950-
.merge(const TextStyle(
951-
fontSize: 0.825 * kBaseFontSize,
952-
height: 1.4,
953-
));
954-
955949
// const _kInlineCodeLeftBracket = '⸤';
956950
// const _kInlineCodeRightBracket = '⸣';
957951
// Some alternatives:

0 commit comments

Comments
 (0)