From 88c27553344fbf9041abcfd3c2871a2a598e8ac6 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Thu, 6 Jun 2024 16:46:13 -0400 Subject: [PATCH] content [nfc]: Move _kCodeBlockStyle to CodeBlockTextStyles --- lib/widgets/code_block.dart | 10 ++++++++++ lib/widgets/content.dart | 10 ++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/widgets/code_block.dart b/lib/widgets/code_block.dart index 0a61f758d2..33fed151f7 100644 --- a/lib/widgets/code_block.dart +++ b/lib/widgets/code_block.dart @@ -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. @@ -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()), @@ -204,6 +210,7 @@ class CodeBlockTextStyles { } CodeBlockTextStyles._({ + required this.plain, required TextStyle hll, required TextStyle c, required TextStyle err, @@ -330,6 +337,8 @@ class CodeBlockTextStyles { _vi = vi, _il = il; + final TextStyle plain; + final TextStyle _hll; final TextStyle _c; final TextStyle _err; @@ -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)!, diff --git a/lib/widgets/content.dart b/lib/widgets/content.dart index cd89d53583..d7233552af 100644 --- a/lib/widgets/content.dart +++ b/lib/widgets/content.dart @@ -580,7 +580,7 @@ class CodeBlock extends StatelessWidget { InlineSpan _buildNodes(List nodes, {required CodeBlockTextStyles styles}) { return TextSpan( - style: _kCodeBlockStyle, + style: styles.plain, children: nodes.map((n) => _buildNode(n, styles: styles)).toList(growable: false)); } @@ -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)]))); } } @@ -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: