diff --git a/lib/custom_widgets/code_field.dart b/lib/custom_widgets/code_field.dart index 79c2673..3d763ee 100644 --- a/lib/custom_widgets/code_field.dart +++ b/lib/custom_widgets/code_field.dart @@ -14,10 +14,20 @@ import 'package:flutter/services.dart'; /// - Visual feedback when code is copied /// - Themed colors that adapt to light/dark mode class CodeField extends StatefulWidget { - const CodeField({super.key, required this.name, required this.codes}); + const CodeField({ + super.key, + required this.name, + required this.codes, + this.backgroundColor, + this.textColor, + }); + final String name; final String codes; + final Color? backgroundColor; + final Color? textColor; + @override State createState() => _CodeFieldState(); } @@ -27,7 +37,9 @@ class _CodeFieldState extends State { @override Widget build(BuildContext context) { return Material( - color: Theme.of(context).colorScheme.onInverseSurface, + color: + widget.backgroundColor ?? + Theme.of(context).colorScheme.onInverseSurface, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -39,12 +51,21 @@ class _CodeFieldState extends State { horizontal: 16.0, vertical: 8, ), - child: Text(widget.name), + child: Text( + widget.name, + style: TextStyle( + color: + widget.textColor ?? + Theme.of(context).colorScheme.onSurface, + ), + ), ), const Spacer(), TextButton.icon( style: TextButton.styleFrom( - foregroundColor: Theme.of(context).colorScheme.onSurface, + foregroundColor: + widget.textColor ?? + Theme.of(context).colorScheme.onSurface, textStyle: const TextStyle(fontWeight: FontWeight.normal), ), onPressed: () async { @@ -64,7 +85,14 @@ class _CodeFieldState extends State { (_copied) ? Icons.done : Icons.content_paste, size: 15, ), - label: Text((_copied) ? "Copied!" : "Copy code"), + label: Text( + (_copied) ? "Copied!" : "Copy code", + style: TextStyle( + color: + widget.textColor ?? + Theme.of(context).colorScheme.onSurface, + ), + ), ), ], ), @@ -75,6 +103,8 @@ class _CodeFieldState extends State { child: Text( widget.codes, style: TextStyle( + color: + widget.textColor ?? Theme.of(context).colorScheme.onSurface, fontFamily: 'JetBrainsMono', package: "gpt_markdown", ), diff --git a/lib/custom_widgets/markdown_config.dart b/lib/custom_widgets/markdown_config.dart index 0864f69..ec22649 100644 --- a/lib/custom_widgets/markdown_config.dart +++ b/lib/custom_widgets/markdown_config.dart @@ -93,6 +93,7 @@ class GptMarkdownConfig { this.components, this.inlineComponents, this.tableBuilder, + this.addNewLineAfterH1 = true, }); /// The direction of the text. @@ -155,6 +156,9 @@ class GptMarkdownConfig { /// The table builder. final TableBuilder? tableBuilder; + /// Whether to add a new line after the h1 tag. + final bool addNewLineAfterH1; + /// A copy of the configuration with the specified parameters. GptMarkdownConfig copyWith({ TextStyle? style, @@ -177,6 +181,7 @@ class GptMarkdownConfig { final List? components, final List? inlineComponents, final TableBuilder? tableBuilder, + final bool? addNewLineAfterH1, }) { return GptMarkdownConfig( style: style ?? this.style, @@ -199,6 +204,7 @@ class GptMarkdownConfig { components: components ?? this.components, inlineComponents: inlineComponents ?? this.inlineComponents, tableBuilder: tableBuilder ?? this.tableBuilder, + addNewLineAfterH1: addNewLineAfterH1 ?? this.addNewLineAfterH1, ); } @@ -222,6 +228,7 @@ class GptMarkdownConfig { maxLines == other.maxLines && overflow == other.overflow && followLinkColor == other.followLinkColor && + addNewLineAfterH1 == other.addNewLineAfterH1 && // latexWorkaround == other.latexWorkaround && // components == other.components && // inlineComponents == other.inlineComponents && diff --git a/lib/gpt_markdown.dart b/lib/gpt_markdown.dart index 3ec7bdb..534fd46 100644 --- a/lib/gpt_markdown.dart +++ b/lib/gpt_markdown.dart @@ -44,6 +44,7 @@ class GptMarkdown extends StatelessWidget { this.components, this.inlineComponents, this.useDollarSignsForLatex = false, + this.addNewLineAfterH1 = true, }); /// The direction of the text. @@ -104,6 +105,9 @@ class GptMarkdown extends StatelessWidget { /// The table builder. final TableBuilder? tableBuilder; + /// Whether to add a new line after the h1 tag. + final bool addNewLineAfterH1; + /// The list of components. /// ```dart /// List components = [ @@ -207,6 +211,7 @@ class GptMarkdown extends StatelessWidget { components: components, inlineComponents: inlineComponents, tableBuilder: tableBuilder, + addNewLineAfterH1: addNewLineAfterH1, ), ), ); diff --git a/lib/markdown_component.dart b/lib/markdown_component.dart index ae5b8bc..65deac6 100644 --- a/lib/markdown_component.dart +++ b/lib/markdown_component.dart @@ -222,10 +222,11 @@ class HTag extends BlockMd { false, )), if (match.namedGroup('hash')!.length == 1) ...[ - const TextSpan( - text: "\n ", - style: TextStyle(fontSize: 0, height: 0), - ), + if (config.addNewLineAfterH1) + const TextSpan( + text: "\n ", + style: TextStyle(fontSize: 0, height: 0), + ), WidgetSpan( child: CustomDivider( height: theme.hrLineThickness,