saminsohag

overflow peramiter added

  1 +## 0.1.6
  2 +
  3 +* `overflow` perameter added.
  4 +
1 ## 0.1.5 5 ## 0.1.5
2 6
3 * Some color changes and highlighted text style changed. 7 * Some color changes and highlighted text style changed.
@@ -178,7 +178,8 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -178,7 +178,8 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
178 debugPrint(url); 178 debugPrint(url);
179 debugPrint(title); 179 debugPrint(title);
180 }, 180 },
181 - maxLines: null, 181 + // maxLines: 3,
  182 + // overflow: TextOverflow.ellipsis,
182 textAlign: TextAlign.justify, 183 textAlign: TextAlign.justify,
183 // textScaler: const TextScaler.linear(1.3), 184 // textScaler: const TextScaler.linear(1.3),
184 textScaler: const TextScaler.linear(1), 185 textScaler: const TextScaler.linear(1),
@@ -186,9 +187,33 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -186,9 +187,33 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
186 // Regular text font size here. 187 // Regular text font size here.
187 fontSize: 15, 188 fontSize: 15,
188 ), 189 ),
189 - latexWorkaround: (tex) =>  
190 - tex.replaceAllMapped(RegExp(r"align\*"),  
191 - (match) => "aligned"), 190 + latexWorkaround: (tex) {
  191 + List<String> stack = [];
  192 + tex = tex.splitMapJoin(
  193 + RegExp(r"\\text\{|\{|\}|\_"),
  194 + onMatch: (p) {
  195 + String input = p[0] ?? "";
  196 + if (input == r"\text{") {
  197 + stack.add(input);
  198 + }
  199 + if (stack.isNotEmpty) {
  200 + if (input == r"{") {
  201 + stack.add(input);
  202 + }
  203 + if (input == r"}") {
  204 + stack.removeLast();
  205 + }
  206 + if (input == r"_") {
  207 + return r"\_";
  208 + }
  209 + }
  210 + return input;
  211 + },
  212 + );
  213 + return tex.replaceAllMapped(
  214 + RegExp(r"align\*"),
  215 + (match) => "aligned");
  216 + },
192 latexBuilder: 217 latexBuilder:
193 (contex, tex, textStyle, inline) { 218 (contex, tex, textStyle, inline) {
194 if (tex.contains(r"\begin{tabular}")) { 219 if (tex.contains(r"\begin{tabular}")) {
@@ -77,10 +77,10 @@ packages: @@ -77,10 +77,10 @@ packages:
77 dependency: transitive 77 dependency: transitive
78 description: 78 description:
79 name: cross_file 79 name: cross_file
80 - sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32" 80 + sha256: "7caf6a750a0c04effbb52a676dce9a4a592e10ad35c34d6d2d0e4811160d5670"
81 url: "https://pub.dev" 81 url: "https://pub.dev"
82 source: hosted 82 source: hosted
83 - version: "0.3.4+1" 83 + version: "0.3.4+2"
84 crypto: 84 crypto:
85 dependency: transitive 85 dependency: transitive
86 description: 86 description:
@@ -154,10 +154,10 @@ packages: @@ -154,10 +154,10 @@ packages:
154 dependency: transitive 154 dependency: transitive
155 description: 155 description:
156 name: flutter_plugin_android_lifecycle 156 name: flutter_plugin_android_lifecycle
157 - sha256: c6b0b4c05c458e1c01ad9bcc14041dd7b1f6783d487be4386f793f47a8a4d03e 157 + sha256: "9d98bd47ef9d34e803d438f17fd32b116d31009f534a6fa5ce3a1167f189a6de"
158 url: "https://pub.dev" 158 url: "https://pub.dev"
159 source: hosted 159 source: hosted
160 - version: "2.0.20" 160 + version: "2.0.21"
161 flutter_svg: 161 flutter_svg:
162 dependency: transitive 162 dependency: transitive
163 description: 163 description:
@@ -182,15 +182,15 @@ packages: @@ -182,15 +182,15 @@ packages:
182 path: ".." 182 path: ".."
183 relative: true 183 relative: true
184 source: path 184 source: path
185 - version: "0.1.5" 185 + version: "0.1.6"
186 http: 186 http:
187 dependency: transitive 187 dependency: transitive
188 description: 188 description:
189 name: http 189 name: http
190 - sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" 190 + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
191 url: "https://pub.dev" 191 url: "https://pub.dev"
192 source: hosted 192 source: hosted
193 - version: "1.2.1" 193 + version: "1.2.2"
194 http_parser: 194 http_parser:
195 dependency: transitive 195 dependency: transitive
196 description: 196 description:
@@ -291,18 +291,18 @@ packages: @@ -291,18 +291,18 @@ packages:
291 dependency: "direct main" 291 dependency: "direct main"
292 description: 292 description:
293 name: path_provider 293 name: path_provider
294 - sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 294 + sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378
295 url: "https://pub.dev" 295 url: "https://pub.dev"
296 source: hosted 296 source: hosted
297 - version: "2.1.3" 297 + version: "2.1.4"
298 path_provider_android: 298 path_provider_android:
299 dependency: transitive 299 dependency: transitive
300 description: 300 description:
301 name: path_provider_android 301 name: path_provider_android
302 - sha256: "30c5aa827a6ae95ce2853cdc5fe3971daaac00f6f081c419c013f7f57bff2f5e" 302 + sha256: "490539678396d4c3c0b06efdaab75ae60675c3e0c66f72bc04c2e2c1e0e2abeb"
303 url: "https://pub.dev" 303 url: "https://pub.dev"
304 source: hosted 304 source: hosted
305 - version: "2.2.7" 305 + version: "2.2.9"
306 path_provider_foundation: 306 path_provider_foundation:
307 dependency: transitive 307 dependency: transitive
308 description: 308 description:
@@ -379,10 +379,10 @@ packages: @@ -379,10 +379,10 @@ packages:
379 dependency: transitive 379 dependency: transitive
380 description: 380 description:
381 name: permission_handler_html 381 name: permission_handler_html
382 - sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d" 382 + sha256: "6cac773d389e045a8d4f85418d07ad58ef9e42a56e063629ce14c4c26344de24"
383 url: "https://pub.dev" 383 url: "https://pub.dev"
384 source: hosted 384 source: hosted
385 - version: "0.1.1" 385 + version: "0.1.2"
386 permission_handler_platform_interface: 386 permission_handler_platform_interface:
387 dependency: transitive 387 dependency: transitive
388 description: 388 description:
@@ -443,10 +443,10 @@ packages: @@ -443,10 +443,10 @@ packages:
443 dependency: transitive 443 dependency: transitive
444 description: 444 description:
445 name: qr 445 name: qr
446 - sha256: "64957a3930367bf97cc211a5af99551d630f2f4625e38af10edd6b19131b64b3" 446 + sha256: "5a1d2586170e172b8a8c8470bbbffd5eb0cd38a66c0d77155ea138d3af3a4445"
447 url: "https://pub.dev" 447 url: "https://pub.dev"
448 source: hosted 448 source: hosted
449 - version: "3.0.1" 449 + version: "3.0.2"
450 sky_engine: 450 sky_engine:
451 dependency: transitive 451 dependency: transitive
452 description: flutter 452 description: flutter
@@ -528,18 +528,18 @@ packages: @@ -528,18 +528,18 @@ packages:
528 dependency: transitive 528 dependency: transitive
529 description: 529 description:
530 name: url_launcher_android 530 name: url_launcher_android
531 - sha256: ceb2625f0c24ade6ef6778d1de0b2e44f2db71fded235eb52295247feba8c5cf 531 + sha256: "94d8ad05f44c6d4e2ffe5567ab4d741b82d62e3c8e288cc1fcea45965edf47c9"
532 url: "https://pub.dev" 532 url: "https://pub.dev"
533 source: hosted 533 source: hosted
534 - version: "6.3.3" 534 + version: "6.3.8"
535 url_launcher_ios: 535 url_launcher_ios:
536 dependency: transitive 536 dependency: transitive
537 description: 537 description:
538 name: url_launcher_ios 538 name: url_launcher_ios
539 - sha256: "7068716403343f6ba4969b4173cbf3b84fc768042124bc2c011e5d782b24fe89" 539 + sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e
540 url: "https://pub.dev" 540 url: "https://pub.dev"
541 source: hosted 541 source: hosted
542 - version: "6.3.0" 542 + version: "6.3.1"
543 url_launcher_linux: 543 url_launcher_linux:
544 dependency: transitive 544 dependency: transitive
545 description: 545 description:
@@ -568,18 +568,18 @@ packages: @@ -568,18 +568,18 @@ packages:
568 dependency: transitive 568 dependency: transitive
569 description: 569 description:
570 name: url_launcher_web 570 name: url_launcher_web
571 - sha256: "8d9e750d8c9338601e709cd0885f95825086bd8b642547f26bda435aade95d8a" 571 + sha256: a36e2d7981122fa185006b216eb6b5b97ede3f9a54b7a511bc966971ab98d049
572 url: "https://pub.dev" 572 url: "https://pub.dev"
573 source: hosted 573 source: hosted
574 - version: "2.3.1" 574 + version: "2.3.2"
575 url_launcher_windows: 575 url_launcher_windows:
576 dependency: transitive 576 dependency: transitive
577 description: 577 description:
578 name: url_launcher_windows 578 name: url_launcher_windows
579 - sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7 579 + sha256: "49c10f879746271804767cb45551ec5592cdab00ee105c06dddde1a98f73b185"
580 url: "https://pub.dev" 580 url: "https://pub.dev"
581 source: hosted 581 source: hosted
582 - version: "3.1.1" 582 + version: "3.1.2"
583 vector_graphics: 583 vector_graphics:
584 dependency: transitive 584 dependency: transitive
585 description: 585 description:
@@ -632,10 +632,10 @@ packages: @@ -632,10 +632,10 @@ packages:
632 dependency: transitive 632 dependency: transitive
633 description: 633 description:
634 name: win32 634 name: win32
635 - sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 635 + sha256: "015002c060f1ae9f41a818f2d5640389cc05283e368be19dc8d77cecb43c40c9"
636 url: "https://pub.dev" 636 url: "https://pub.dev"
637 source: hosted 637 source: hosted
638 - version: "5.5.1" 638 + version: "5.5.3"
639 xdg_directories: 639 xdg_directories:
640 dependency: transitive 640 dependency: transitive
641 description: 641 description:
  1 +import 'package:flutter/material.dart';
  2 +
  3 +class GptMarkdownConfig {
  4 + const GptMarkdownConfig({
  5 + this.style,
  6 + this.textDirection = TextDirection.ltr,
  7 + this.onLinkTab,
  8 + this.textAlign,
  9 + this.textScaler,
  10 + this.latexWorkaround,
  11 + this.latexBuilder,
  12 + this.followLinkColor = false,
  13 + this.codeBuilder,
  14 + this.maxLines,
  15 + this.overflow,
  16 + });
  17 + final TextDirection textDirection;
  18 + final TextStyle? style;
  19 + final TextAlign? textAlign;
  20 + final TextScaler? textScaler;
  21 + final void Function(String url, String title)? onLinkTab;
  22 + final String Function(String tex)? latexWorkaround;
  23 + final Widget Function(
  24 + BuildContext context, String tex, TextStyle textStyle, bool inline)?
  25 + latexBuilder;
  26 + final bool followLinkColor;
  27 + final Widget Function(BuildContext context, String name, String code)?
  28 + codeBuilder;
  29 + final int? maxLines;
  30 + final TextOverflow? overflow;
  31 + GptMarkdownConfig copyWith({
  32 + TextStyle? style,
  33 + TextDirection? textDirection,
  34 + final void Function(String url, String title)? onLinkTab,
  35 + final TextAlign? textAlign,
  36 + final TextScaler? textScaler,
  37 + final String Function(String tex)? latexWorkaround,
  38 + final Widget Function(
  39 + BuildContext context, String tex, TextStyle textStyle, bool inline)?
  40 + latexBuilder,
  41 + bool? followLinkColor,
  42 + final Widget Function(BuildContext context, String name, String code)?
  43 + codeBuilder,
  44 + final int? maxLines,
  45 + final TextOverflow? overflow,
  46 + }) {
  47 + return GptMarkdownConfig(
  48 + style: style ?? this.style,
  49 + textDirection: textDirection ?? this.textDirection,
  50 + onLinkTab: onLinkTab ?? this.onLinkTab,
  51 + textAlign: textAlign ?? this.textAlign,
  52 + textScaler: textScaler ?? this.textScaler,
  53 + latexWorkaround: latexWorkaround ?? this.latexWorkaround,
  54 + latexBuilder: latexBuilder ?? this.latexBuilder,
  55 + followLinkColor: followLinkColor ?? this.followLinkColor,
  56 + codeBuilder: codeBuilder ?? this.codeBuilder,
  57 + maxLines: maxLines ?? this.maxLines,
  58 + overflow: overflow ?? this.overflow,
  59 + );
  60 + }
  61 +}
1 library tex_markdown; 1 library tex_markdown;
2 2
3 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
  4 +import 'package:gpt_markdown/custom_widgets/markdow_config.dart';
4 5
5 import 'md_widget.dart'; 6 import 'md_widget.dart';
6 7
@@ -19,6 +20,7 @@ class TexMarkdown extends StatelessWidget { @@ -19,6 +20,7 @@ class TexMarkdown extends StatelessWidget {
19 this.latexBuilder, 20 this.latexBuilder,
20 this.codeBuilder, 21 this.codeBuilder,
21 this.maxLines, 22 this.maxLines,
  23 + this.overflow,
22 }); 24 });
23 final TextDirection textDirection; 25 final TextDirection textDirection;
24 final String data; 26 final String data;
@@ -28,6 +30,7 @@ class TexMarkdown extends StatelessWidget { @@ -28,6 +30,7 @@ class TexMarkdown extends StatelessWidget {
28 final void Function(String url, String title)? onLinkTab; 30 final void Function(String url, String title)? onLinkTab;
29 final String Function(String tex)? latexWorkaround; 31 final String Function(String tex)? latexWorkaround;
30 final int? maxLines; 32 final int? maxLines;
  33 + final TextOverflow? overflow;
31 final Widget Function( 34 final Widget Function(
32 BuildContext context, String tex, TextStyle style, bool inline)? 35 BuildContext context, String tex, TextStyle style, bool inline)?
33 latexBuilder; 36 latexBuilder;
@@ -61,16 +64,19 @@ class TexMarkdown extends StatelessWidget { @@ -61,16 +64,19 @@ class TexMarkdown extends StatelessWidget {
61 return ClipRRect( 64 return ClipRRect(
62 child: MdWidget( 65 child: MdWidget(
63 tex, 66 tex,
64 - textDirection: textDirection,  
65 - style: style,  
66 - onLinkTab: onLinkTab,  
67 - textAlign: textAlign,  
68 - textScaler: textScaler,  
69 - followLinkColor: followLinkColor,  
70 - latexWorkaround: latexWorkaround,  
71 - latexBuilder: latexBuilder,  
72 - codeBuilder: codeBuilder,  
73 - maxLines: maxLines, 67 + config: GptMarkdownConfig(
  68 + textDirection: textDirection,
  69 + style: style,
  70 + onLinkTab: onLinkTab,
  71 + textAlign: textAlign,
  72 + textScaler: textScaler,
  73 + followLinkColor: followLinkColor,
  74 + latexWorkaround: latexWorkaround,
  75 + latexBuilder: latexBuilder,
  76 + codeBuilder: codeBuilder,
  77 + maxLines: maxLines,
  78 + overflow: overflow,
  79 + ),
74 )); 80 ));
75 } 81 }
76 } 82 }
@@ -5,6 +5,7 @@ import 'package:flutter_math_fork/flutter_math.dart'; @@ -5,6 +5,7 @@ import 'package:flutter_math_fork/flutter_math.dart';
5 import 'package:gpt_markdown/custom_widgets/custom_divider.dart'; 5 import 'package:gpt_markdown/custom_widgets/custom_divider.dart';
6 import 'package:gpt_markdown/custom_widgets/custom_error_image.dart'; 6 import 'package:gpt_markdown/custom_widgets/custom_error_image.dart';
7 import 'package:gpt_markdown/custom_widgets/custom_rb_cb.dart'; 7 import 'package:gpt_markdown/custom_widgets/custom_rb_cb.dart';
  8 +import 'package:gpt_markdown/custom_widgets/markdow_config.dart';
8 import 'package:gpt_markdown/custom_widgets/unordered_ordered_list.dart'; 9 import 'package:gpt_markdown/custom_widgets/unordered_ordered_list.dart';
9 import 'md_widget.dart'; 10 import 'md_widget.dart';
10 11
@@ -35,15 +36,7 @@ abstract class MarkdownComponent { @@ -35,15 +36,7 @@ abstract class MarkdownComponent {
35 static List<InlineSpan> generate( 36 static List<InlineSpan> generate(
36 BuildContext context, 37 BuildContext context,
37 String text, 38 String text,
38 - TextStyle? style,  
39 - TextDirection textDirection,  
40 - final void Function(String url, String title)? onLinkTab,  
41 - final String Function(String tex)? latexWorkaround,  
42 - final Widget Function(  
43 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
44 - latexBuilder,  
45 - final Widget Function(BuildContext context, String name, String code)?  
46 - codeBuilder, 39 + final GptMarkdownConfig config,
47 ) { 40 ) {
48 List<InlineSpan> spans = []; 41 List<InlineSpan> spans = [];
49 List<String> regexes = 42 List<String> regexes =
@@ -65,12 +58,7 @@ abstract class MarkdownComponent { @@ -65,12 +58,7 @@ abstract class MarkdownComponent {
65 spans.add(each.span( 58 spans.add(each.span(
66 context, 59 context,
67 element, 60 element,
68 - style,  
69 - textDirection,  
70 - onLinkTab,  
71 - latexWorkaround,  
72 - latexBuilder,  
73 - codeBuilder, 61 + config,
74 )); 62 ));
75 } else { 63 } else {
76 if (each is BlockMd) { 64 if (each is BlockMd) {
@@ -80,25 +68,20 @@ abstract class MarkdownComponent { @@ -80,25 +68,20 @@ abstract class MarkdownComponent {
80 style: TextStyle( 68 style: TextStyle(
81 fontSize: 0, 69 fontSize: 0,
82 height: 0, 70 height: 0,
83 - color: style?.color, 71 + color: config.style?.color,
84 ), 72 ),
85 ), 73 ),
86 each.span( 74 each.span(
87 context, 75 context,
88 element, 76 element,
89 - style,  
90 - textDirection,  
91 - onLinkTab,  
92 - latexWorkaround,  
93 - latexBuilder,  
94 - codeBuilder, 77 + config,
95 ), 78 ),
96 TextSpan( 79 TextSpan(
97 text: "\n ", 80 text: "\n ",
98 style: TextStyle( 81 style: TextStyle(
99 fontSize: 0, 82 fontSize: 0,
100 height: 0, 83 height: 0,
101 - color: style?.color, 84 + color: config.style?.color,
102 ), 85 ),
103 ), 86 ),
104 ]); 87 ]);
@@ -113,7 +96,7 @@ abstract class MarkdownComponent { @@ -113,7 +96,7 @@ abstract class MarkdownComponent {
113 spans.add( 96 spans.add(
114 TextSpan( 97 TextSpan(
115 text: p0, 98 text: p0,
116 - style: style, 99 + style: config.style,
117 ), 100 ),
118 ); 101 );
119 return ""; 102 return "";
@@ -126,15 +109,7 @@ abstract class MarkdownComponent { @@ -126,15 +109,7 @@ abstract class MarkdownComponent {
126 InlineSpan span( 109 InlineSpan span(
127 BuildContext context, 110 BuildContext context,
128 String text, 111 String text,
129 - TextStyle? style,  
130 - TextDirection textDirection,  
131 - final void Function(String url, String title)? onLinkTab,  
132 - final String Function(String tex)? latexWorkaround,  
133 - final Widget Function(  
134 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
135 - latexBuilder,  
136 - final Widget Function(BuildContext context, String name, String code)?  
137 - codeBuilder, 112 + final GptMarkdownConfig config,
138 ); 113 );
139 114
140 RegExp get exp; 115 RegExp get exp;
@@ -150,15 +125,7 @@ abstract class InlineMd extends MarkdownComponent { @@ -150,15 +125,7 @@ abstract class InlineMd extends MarkdownComponent {
150 InlineSpan span( 125 InlineSpan span(
151 BuildContext context, 126 BuildContext context,
152 String text, 127 String text,
153 - TextStyle? style,  
154 - TextDirection textDirection,  
155 - final void Function(String url, String title)? onLinkTab,  
156 - final String Function(String tex)? latexWorkaround,  
157 - final Widget Function(  
158 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
159 - latexBuilder,  
160 - final Widget Function(BuildContext context, String name, String code)?  
161 - codeBuilder, 128 + final GptMarkdownConfig config,
162 ); 129 );
163 } 130 }
164 131
@@ -170,26 +137,13 @@ abstract class BlockMd extends MarkdownComponent { @@ -170,26 +137,13 @@ abstract class BlockMd extends MarkdownComponent {
170 InlineSpan span( 137 InlineSpan span(
171 BuildContext context, 138 BuildContext context,
172 String text, 139 String text,
173 - TextStyle? style,  
174 - TextDirection textDirection,  
175 - final void Function(String url, String title)? onLinkTab,  
176 - final String Function(String tex)? latexWorkaround,  
177 - final Widget Function(  
178 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
179 - latexBuilder,  
180 - final Widget Function(BuildContext context, String name, String code)?  
181 - codeBuilder, 140 + final GptMarkdownConfig config,
182 ) { 141 ) {
183 return WidgetSpan( 142 return WidgetSpan(
184 child: build( 143 child: build(
185 context, 144 context,
186 text, 145 text,
187 - style,  
188 - textDirection,  
189 - onLinkTab,  
190 - latexWorkaround,  
191 - latexBuilder,  
192 - codeBuilder, 146 + config,
193 ), 147 ),
194 alignment: PlaceholderAlignment.middle, 148 alignment: PlaceholderAlignment.middle,
195 ); 149 );
@@ -198,15 +152,7 @@ abstract class BlockMd extends MarkdownComponent { @@ -198,15 +152,7 @@ abstract class BlockMd extends MarkdownComponent {
198 Widget build( 152 Widget build(
199 BuildContext context, 153 BuildContext context,
200 String text, 154 String text,
201 - TextStyle? style,  
202 - TextDirection textDirection,  
203 - final void Function(String url, String title)? onLinkTab,  
204 - final String Function(String tex)? latexWorkaround,  
205 - final Widget Function(  
206 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
207 - latexBuilder,  
208 - final Widget Function(BuildContext context, String name, String code)?  
209 - codeBuilder, 155 + final GptMarkdownConfig config,
210 ); 156 );
211 } 157 }
212 158
@@ -218,54 +164,43 @@ class HTag extends BlockMd { @@ -218,54 +164,43 @@ class HTag extends BlockMd {
218 Widget build( 164 Widget build(
219 BuildContext context, 165 BuildContext context,
220 String text, 166 String text,
221 - TextStyle? style,  
222 - TextDirection textDirection,  
223 - final void Function(String url, String title)? onLinkTab,  
224 - final String Function(String tex)? latexWorkaround,  
225 - final Widget Function(  
226 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
227 - latexBuilder,  
228 - final Widget Function(BuildContext context, String name, String code)?  
229 - codeBuilder, 167 + final GptMarkdownConfig config,
230 ) { 168 ) {
231 var match = exp.firstMatch(text.trim()); 169 var match = exp.firstMatch(text.trim());
  170 + var conf = config.copyWith(
  171 + style: [
  172 + Theme.of(context)
  173 + .textTheme
  174 + .headlineLarge
  175 + ?.copyWith(color: config.style?.color),
  176 + Theme.of(context)
  177 + .textTheme
  178 + .headlineMedium
  179 + ?.copyWith(color: config.style?.color),
  180 + Theme.of(context)
  181 + .textTheme
  182 + .headlineSmall
  183 + ?.copyWith(color: config.style?.color),
  184 + Theme.of(context)
  185 + .textTheme
  186 + .titleLarge
  187 + ?.copyWith(color: config.style?.color),
  188 + Theme.of(context)
  189 + .textTheme
  190 + .titleMedium
  191 + ?.copyWith(color: config.style?.color),
  192 + Theme.of(context)
  193 + .textTheme
  194 + .titleSmall
  195 + ?.copyWith(color: config.style?.color),
  196 + ][match![1]!.length - 1]);
232 return Text.rich( 197 return Text.rich(
233 TextSpan( 198 TextSpan(
234 children: [ 199 children: [
235 ...(MarkdownComponent.generate( 200 ...(MarkdownComponent.generate(
236 context, 201 context,
237 - "${match?[2]}",  
238 - [  
239 - Theme.of(context)  
240 - .textTheme  
241 - .headlineLarge  
242 - ?.copyWith(color: style?.color),  
243 - Theme.of(context)  
244 - .textTheme  
245 - .headlineMedium  
246 - ?.copyWith(color: style?.color),  
247 - Theme.of(context)  
248 - .textTheme  
249 - .headlineSmall  
250 - ?.copyWith(color: style?.color),  
251 - Theme.of(context)  
252 - .textTheme  
253 - .titleLarge  
254 - ?.copyWith(color: style?.color),  
255 - Theme.of(context)  
256 - .textTheme  
257 - .titleMedium  
258 - ?.copyWith(color: style?.color),  
259 - Theme.of(context)  
260 - .textTheme  
261 - .titleSmall  
262 - ?.copyWith(color: style?.color),  
263 - ][match![1]!.length - 1],  
264 - textDirection,  
265 - (url, title) {},  
266 - latexWorkaround,  
267 - latexBuilder,  
268 - codeBuilder, 202 + "${match[2]}",
  203 + conf,
269 )), 204 )),
270 if (match[1]!.length == 1) ...[ 205 if (match[1]!.length == 1) ...[
271 const TextSpan( 206 const TextSpan(
@@ -275,13 +210,16 @@ class HTag extends BlockMd { @@ -275,13 +210,16 @@ class HTag extends BlockMd {
275 WidgetSpan( 210 WidgetSpan(
276 child: CustomDivider( 211 child: CustomDivider(
277 height: 2, 212 height: 2,
278 - color: style?.color ?? Theme.of(context).colorScheme.outline, 213 + color: config.style?.color ??
  214 + Theme.of(context).colorScheme.outline,
279 ), 215 ),
280 ), 216 ),
281 ], 217 ],
282 ], 218 ],
283 ), 219 ),
284 - textDirection: textDirection, 220 + textDirection: config.textDirection,
  221 + overflow: config.overflow,
  222 + maxLines: config.maxLines,
285 ); 223 );
286 } 224 }
287 } 225 }
@@ -293,21 +231,13 @@ class NewLines extends InlineMd { @@ -293,21 +231,13 @@ class NewLines extends InlineMd {
293 InlineSpan span( 231 InlineSpan span(
294 BuildContext context, 232 BuildContext context,
295 String text, 233 String text,
296 - TextStyle? style,  
297 - TextDirection textDirection,  
298 - final void Function(String url, String title)? onLinkTab,  
299 - final String Function(String tex)? latexWorkaround,  
300 - final Widget Function(  
301 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
302 - latexBuilder,  
303 - final Widget Function(BuildContext context, String name, String code)?  
304 - codeBuilder, 234 + final GptMarkdownConfig config,
305 ) { 235 ) {
306 return TextSpan( 236 return TextSpan(
307 text: "\n\n\n\n", 237 text: "\n\n\n\n",
308 style: TextStyle( 238 style: TextStyle(
309 fontSize: 6, 239 fontSize: 6,
310 - color: style?.color, 240 + color: config.style?.color,
311 ), 241 ),
312 ); 242 );
313 } 243 }
@@ -321,19 +251,11 @@ class HrLine extends BlockMd { @@ -321,19 +251,11 @@ class HrLine extends BlockMd {
321 Widget build( 251 Widget build(
322 BuildContext context, 252 BuildContext context,
323 String text, 253 String text,
324 - TextStyle? style,  
325 - TextDirection textDirection,  
326 - final void Function(String url, String title)? onLinkTab,  
327 - final String Function(String tex)? latexWorkaround,  
328 - final Widget Function(  
329 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
330 - latexBuilder,  
331 - final Widget Function(BuildContext context, String name, String code)?  
332 - codeBuilder, 254 + final GptMarkdownConfig config,
333 ) { 255 ) {
334 return CustomDivider( 256 return CustomDivider(
335 height: 2, 257 height: 2,
336 - color: style?.color ?? Theme.of(context).colorScheme.outline, 258 + color: config.style?.color ?? Theme.of(context).colorScheme.outline,
337 ); 259 );
338 } 260 }
339 } 261 }
@@ -348,28 +270,15 @@ class CheckBoxMd extends BlockMd { @@ -348,28 +270,15 @@ class CheckBoxMd extends BlockMd {
348 Widget build( 270 Widget build(
349 BuildContext context, 271 BuildContext context,
350 String text, 272 String text,
351 - TextStyle? style,  
352 - TextDirection textDirection,  
353 - final void Function(String url, String title)? onLinkTab,  
354 - final String Function(String tex)? latexWorkaround,  
355 - final Widget Function(  
356 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
357 - latexBuilder,  
358 - final Widget Function(BuildContext context, String name, String code)?  
359 - codeBuilder, 273 + final GptMarkdownConfig config,
360 ) { 274 ) {
361 var match = exp.firstMatch(text.trim()); 275 var match = exp.firstMatch(text.trim());
362 return CustomCb( 276 return CustomCb(
363 value: ("${match?[1]}" == "x"), 277 value: ("${match?[1]}" == "x"),
364 - textDirection: textDirection, 278 + textDirection: config.textDirection,
365 child: MdWidget( 279 child: MdWidget(
366 "${match?[2]}", 280 "${match?[2]}",
367 - onLinkTab: onLinkTab,  
368 - textDirection: textDirection,  
369 - style: style,  
370 - latexWorkaround: latexWorkaround,  
371 - latexBuilder: latexBuilder,  
372 - codeBuilder: codeBuilder, 281 + config: config,
373 ), 282 ),
374 ); 283 );
375 } 284 }
@@ -385,28 +294,15 @@ class RadioButtonMd extends BlockMd { @@ -385,28 +294,15 @@ class RadioButtonMd extends BlockMd {
385 Widget build( 294 Widget build(
386 BuildContext context, 295 BuildContext context,
387 String text, 296 String text,
388 - TextStyle? style,  
389 - TextDirection textDirection,  
390 - final void Function(String url, String title)? onLinkTab,  
391 - final String Function(String tex)? latexWorkaround,  
392 - final Widget Function(  
393 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
394 - latexBuilder,  
395 - final Widget Function(BuildContext context, String name, String code)?  
396 - codeBuilder, 297 + final GptMarkdownConfig config,
397 ) { 298 ) {
398 var match = exp.firstMatch(text.trim()); 299 var match = exp.firstMatch(text.trim());
399 return CustomRb( 300 return CustomRb(
400 value: ("${match?[1]}" == "x"), 301 value: ("${match?[1]}" == "x"),
401 - textDirection: textDirection, 302 + textDirection: config.textDirection,
402 child: MdWidget( 303 child: MdWidget(
403 "${match?[2]}", 304 "${match?[2]}",
404 - onLinkTab: onLinkTab,  
405 - textDirection: textDirection,  
406 - style: style,  
407 - latexWorkaround: latexWorkaround,  
408 - latexBuilder: latexBuilder,  
409 - codeBuilder: codeBuilder, 305 + config: config,
410 ), 306 ),
411 ); 307 );
412 } 308 }
@@ -422,15 +318,7 @@ class IndentMd extends BlockMd { @@ -422,15 +318,7 @@ class IndentMd extends BlockMd {
422 Widget build( 318 Widget build(
423 BuildContext context, 319 BuildContext context,
424 String text, 320 String text,
425 - TextStyle? style,  
426 - TextDirection textDirection,  
427 - final void Function(String url, String title)? onLinkTab,  
428 - final String Function(String tex)? latexWorkaround,  
429 - final Widget Function(  
430 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
431 - latexBuilder,  
432 - final Widget Function(BuildContext context, String name, String code)?  
433 - codeBuilder, 321 + final GptMarkdownConfig config,
434 ) { 322 ) {
435 [ 323 [
436 r"\\\[(.*?)\\\]", 324 r"\\\[(.*?)\\\]",
@@ -440,21 +328,17 @@ class IndentMd extends BlockMd { @@ -440,21 +328,17 @@ class IndentMd extends BlockMd {
440 var match = exp.firstMatch(text); 328 var match = exp.firstMatch(text);
441 int spaces = (match?[1] ?? "").length; 329 int spaces = (match?[1] ?? "").length;
442 return UnorderedListView( 330 return UnorderedListView(
443 - bulletColor: style?.color, 331 + bulletColor: config.style?.color,
444 padding: spaces * 5, 332 padding: spaces * 5,
445 bulletSize: 0, 333 bulletSize: 0,
446 - textDirection: textDirection, 334 + textDirection: config.textDirection,
447 child: RichText( 335 child: RichText(
448 text: TextSpan( 336 text: TextSpan(
449 children: MarkdownComponent.generate( 337 children: MarkdownComponent.generate(
450 - context,  
451 - "${match?[2]}",  
452 - style,  
453 - textDirection,  
454 - onLinkTab,  
455 - latexWorkaround,  
456 - latexBuilder,  
457 - codeBuilder), 338 + context,
  339 + "${match?[2]}",
  340 + config,
  341 + ),
458 )), 342 )),
459 ); 343 );
460 } 344 }
@@ -470,30 +354,17 @@ class UnOrderedList extends BlockMd { @@ -470,30 +354,17 @@ class UnOrderedList extends BlockMd {
470 Widget build( 354 Widget build(
471 BuildContext context, 355 BuildContext context,
472 String text, 356 String text,
473 - TextStyle? style,  
474 - TextDirection textDirection,  
475 - final void Function(String url, String title)? onLinkTab,  
476 - final String Function(String tex)? latexWorkaround,  
477 - final Widget Function(  
478 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
479 - latexBuilder,  
480 - final Widget Function(BuildContext context, String name, String code)?  
481 - codeBuilder, 357 + final GptMarkdownConfig config,
482 ) { 358 ) {
483 var match = exp.firstMatch(text); 359 var match = exp.firstMatch(text);
484 return UnorderedListView( 360 return UnorderedListView(
485 - bulletColor: style?.color, 361 + bulletColor: config.style?.color,
486 padding: 10.0, 362 padding: 10.0,
487 bulletSize: 3, 363 bulletSize: 3,
488 - textDirection: textDirection, 364 + textDirection: config.textDirection,
489 child: MdWidget( 365 child: MdWidget(
490 "${match?[1]}", 366 "${match?[1]}",
491 - onLinkTab: onLinkTab,  
492 - textDirection: textDirection,  
493 - style: style,  
494 - latexWorkaround: latexWorkaround,  
495 - latexBuilder: latexBuilder,  
496 - codeBuilder: codeBuilder, 367 + config: config,
497 ), 368 ),
498 ); 369 );
499 } 370 }
@@ -510,29 +381,19 @@ class OrderedList extends BlockMd { @@ -510,29 +381,19 @@ class OrderedList extends BlockMd {
510 Widget build( 381 Widget build(
511 BuildContext context, 382 BuildContext context,
512 String text, 383 String text,
513 - TextStyle? style,  
514 - TextDirection textDirection,  
515 - final void Function(String url, String title)? onLinkTab,  
516 - final String Function(String tex)? latexWorkaround,  
517 - final Widget Function(  
518 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
519 - latexBuilder,  
520 - final Widget Function(BuildContext context, String name, String code)?  
521 - codeBuilder, 384 + final GptMarkdownConfig config,
522 ) { 385 ) {
523 var match = exp.firstMatch(text.trim()); 386 var match = exp.firstMatch(text.trim());
  387 + var conf = config.copyWith(
  388 + style: (config.style ?? const TextStyle())
  389 + .copyWith(fontWeight: FontWeight.w100));
524 return OrderedListView( 390 return OrderedListView(
525 no: "${match?[1]}", 391 no: "${match?[1]}",
526 - textDirection: textDirection,  
527 - style: (style ?? const TextStyle()).copyWith(fontWeight: FontWeight.w100), 392 + textDirection: config.textDirection,
  393 + style: conf.style,
528 child: MdWidget( 394 child: MdWidget(
529 "${match?[2]}", 395 "${match?[2]}",
530 - onLinkTab: onLinkTab,  
531 - textDirection: textDirection,  
532 - style: style,  
533 - latexWorkaround: latexWorkaround,  
534 - latexBuilder: latexBuilder,  
535 - codeBuilder: codeBuilder, 396 + config: conf,
536 ), 397 ),
537 ); 398 );
538 } 399 }
@@ -546,20 +407,11 @@ class HighlightedText extends InlineMd { @@ -546,20 +407,11 @@ class HighlightedText extends InlineMd {
546 InlineSpan span( 407 InlineSpan span(
547 BuildContext context, 408 BuildContext context,
548 String text, 409 String text,
549 - TextStyle? style,  
550 - TextDirection textDirection,  
551 - final void Function(String url, String title)? onLinkTab,  
552 - final String Function(String tex)? latexWorkaround,  
553 - final Widget Function(  
554 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
555 - latexBuilder,  
556 - final Widget Function(BuildContext context, String name, String code)?  
557 - codeBuilder, 410 + final GptMarkdownConfig config,
558 ) { 411 ) {
559 var match = exp.firstMatch(text.trim()); 412 var match = exp.firstMatch(text.trim());
560 - return TextSpan(  
561 - text: match?[1],  
562 - style: style?.copyWith( 413 + var conf = config.copyWith(
  414 + style: config.style?.copyWith(
563 fontWeight: FontWeight.bold, 415 fontWeight: FontWeight.bold,
564 background: Paint() 416 background: Paint()
565 ..color = Theme.of(context).colorScheme.onInverseSurface 417 ..color = Theme.of(context).colorScheme.onInverseSurface
@@ -574,6 +426,10 @@ class HighlightedText extends InlineMd { @@ -574,6 +426,10 @@ class HighlightedText extends InlineMd {
574 ..strokeJoin = StrokeJoin.round, 426 ..strokeJoin = StrokeJoin.round,
575 ), 427 ),
576 ); 428 );
  429 + return TextSpan(
  430 + text: match?[1],
  431 + style: conf.style,
  432 + );
577 } 433 }
578 } 434 }
579 435
@@ -586,31 +442,19 @@ class BoldMd extends InlineMd { @@ -586,31 +442,19 @@ class BoldMd extends InlineMd {
586 InlineSpan span( 442 InlineSpan span(
587 BuildContext context, 443 BuildContext context,
588 String text, 444 String text,
589 - TextStyle? style,  
590 - TextDirection textDirection,  
591 - final void Function(String url, String title)? onLinkTab,  
592 - final String Function(String tex)? latexWorkaround,  
593 - final Widget Function(  
594 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
595 - latexBuilder,  
596 - final Widget Function(BuildContext context, String name, String code)?  
597 - codeBuilder, 445 + final GptMarkdownConfig config,
598 ) { 446 ) {
599 var match = exp.firstMatch(text.trim()); 447 var match = exp.firstMatch(text.trim());
  448 + var conf = config.copyWith(
  449 + style: config.style?.copyWith(fontWeight: FontWeight.bold) ??
  450 + const TextStyle(fontWeight: FontWeight.bold));
600 return TextSpan( 451 return TextSpan(
601 children: MarkdownComponent.generate( 452 children: MarkdownComponent.generate(
602 context, 453 context,
603 "${match?[1]}", 454 "${match?[1]}",
604 - style?.copyWith(fontWeight: FontWeight.bold) ??  
605 - const TextStyle(fontWeight: FontWeight.w900),  
606 - textDirection,  
607 - onLinkTab,  
608 - latexWorkaround,  
609 - latexBuilder,  
610 - codeBuilder, 455 + conf,
611 ), 456 ),
612 - style: style?.copyWith(fontWeight: FontWeight.bold) ??  
613 - const TextStyle(fontWeight: FontWeight.bold), 457 + style: conf.style,
614 ); 458 );
615 } 459 }
616 } 460 }
@@ -626,22 +470,14 @@ class LatexMathMultyLine extends BlockMd { @@ -626,22 +470,14 @@ class LatexMathMultyLine extends BlockMd {
626 Widget build( 470 Widget build(
627 BuildContext context, 471 BuildContext context,
628 String text, 472 String text,
629 - TextStyle? style,  
630 - TextDirection textDirection,  
631 - void Function(String url, String title)? onLinkTab,  
632 - String Function(String tex)? latexWorkaround,  
633 - Widget Function(  
634 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
635 - latexBuilder,  
636 - Widget Function(BuildContext context, String name, String code)?  
637 - codeBuilder, 473 + final GptMarkdownConfig config,
638 ) { 474 ) {
639 var p0 = exp.firstMatch(text.trim()); 475 var p0 = exp.firstMatch(text.trim());
640 p0?.group(0); 476 p0?.group(0);
641 String mathText = p0?[1] ?? p0?[2] ?? ""; 477 String mathText = p0?[1] ?? p0?[2] ?? "";
642 - var workaround = latexWorkaround ?? (String tex) => tex; 478 + var workaround = config.latexWorkaround ?? (String tex) => tex;
643 479
644 - var builder = latexBuilder ?? 480 + var builder = config.latexBuilder ??
645 (BuildContext context, String tex, TextStyle textStyle, bool inline) => 481 (BuildContext context, String tex, TextStyle textStyle, bool inline) =>
646 Math.tex( 482 Math.tex(
647 tex, 483 tex,
@@ -653,17 +489,18 @@ class LatexMathMultyLine extends BlockMd { @@ -653,17 +489,18 @@ class LatexMathMultyLine extends BlockMd {
653 ), 489 ),
654 options: MathOptions( 490 options: MathOptions(
655 sizeUnderTextStyle: MathSize.large, 491 sizeUnderTextStyle: MathSize.large,
656 - color: style?.color ?? Theme.of(context).colorScheme.onSurface,  
657 - fontSize: style?.fontSize ?? 492 + color: config.style?.color ??
  493 + Theme.of(context).colorScheme.onSurface,
  494 + fontSize: config.style?.fontSize ??
658 Theme.of(context).textTheme.bodyMedium?.fontSize, 495 Theme.of(context).textTheme.bodyMedium?.fontSize,
659 mathFontOptions: FontOptions( 496 mathFontOptions: FontOptions(
660 fontFamily: "Main", 497 fontFamily: "Main",
661 - fontWeight: style?.fontWeight ?? FontWeight.normal, 498 + fontWeight: config.style?.fontWeight ?? FontWeight.normal,
662 fontShape: FontStyle.normal, 499 fontShape: FontStyle.normal,
663 ), 500 ),
664 textFontOptions: FontOptions( 501 textFontOptions: FontOptions(
665 fontFamily: "Main", 502 fontFamily: "Main",
666 - fontWeight: style?.fontWeight ?? FontWeight.normal, 503 + fontWeight: config.style?.fontWeight ?? FontWeight.normal,
667 fontShape: FontStyle.normal, 504 fontShape: FontStyle.normal,
668 ), 505 ),
669 style: MathStyle.display, 506 style: MathStyle.display,
@@ -671,7 +508,7 @@ class LatexMathMultyLine extends BlockMd { @@ -671,7 +508,7 @@ class LatexMathMultyLine extends BlockMd {
671 onErrorFallback: (err) { 508 onErrorFallback: (err) {
672 return Text( 509 return Text(
673 workaround(mathText), 510 workaround(mathText),
674 - textDirection: textDirection, 511 + textDirection: config.textDirection,
675 style: textStyle.copyWith( 512 style: textStyle.copyWith(
676 color: (!kDebugMode) 513 color: (!kDebugMode)
677 ? null 514 ? null
@@ -679,8 +516,8 @@ class LatexMathMultyLine extends BlockMd { @@ -679,8 +516,8 @@ class LatexMathMultyLine extends BlockMd {
679 ); 516 );
680 }, 517 },
681 ); 518 );
682 - return builder(  
683 - context, workaround(mathText), style ?? const TextStyle(), false); 519 + return builder(context, workaround(mathText),
  520 + config.style ?? const TextStyle(), false);
684 } 521 }
685 } 522 }
686 523
@@ -699,21 +536,13 @@ class LatexMath extends InlineMd { @@ -699,21 +536,13 @@ class LatexMath extends InlineMd {
699 InlineSpan span( 536 InlineSpan span(
700 BuildContext context, 537 BuildContext context,
701 String text, 538 String text,
702 - TextStyle? style,  
703 - TextDirection textDirection,  
704 - final void Function(String url, String title)? onLinkTab,  
705 - final String Function(String tex)? latexWorkaround,  
706 - final Widget Function(  
707 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
708 - latexBuilder,  
709 - final Widget Function(BuildContext context, String name, String code)?  
710 - codeBuilder, 539 + final GptMarkdownConfig config,
711 ) { 540 ) {
712 var p0 = exp.firstMatch(text.trim()); 541 var p0 = exp.firstMatch(text.trim());
713 p0?.group(0); 542 p0?.group(0);
714 String mathText = p0?[1]?.toString() ?? ""; 543 String mathText = p0?[1]?.toString() ?? "";
715 - var workaround = latexWorkaround ?? (String tex) => tex;  
716 - var builder = latexBuilder ?? 544 + var workaround = config.latexWorkaround ?? (String tex) => tex;
  545 + var builder = config.latexBuilder ??
717 (BuildContext context, String tex, TextStyle textStyle, bool inline) => 546 (BuildContext context, String tex, TextStyle textStyle, bool inline) =>
718 Math.tex( 547 Math.tex(
719 tex, 548 tex,
@@ -725,17 +554,18 @@ class LatexMath extends InlineMd { @@ -725,17 +554,18 @@ class LatexMath extends InlineMd {
725 ), 554 ),
726 options: MathOptions( 555 options: MathOptions(
727 sizeUnderTextStyle: MathSize.large, 556 sizeUnderTextStyle: MathSize.large,
728 - color: style?.color ?? Theme.of(context).colorScheme.onSurface,  
729 - fontSize: style?.fontSize ?? 557 + color: config.style?.color ??
  558 + Theme.of(context).colorScheme.onSurface,
  559 + fontSize: config.style?.fontSize ??
730 Theme.of(context).textTheme.bodyMedium?.fontSize, 560 Theme.of(context).textTheme.bodyMedium?.fontSize,
731 mathFontOptions: FontOptions( 561 mathFontOptions: FontOptions(
732 fontFamily: "Main", 562 fontFamily: "Main",
733 - fontWeight: style?.fontWeight ?? FontWeight.normal, 563 + fontWeight: config.style?.fontWeight ?? FontWeight.normal,
734 fontShape: FontStyle.normal, 564 fontShape: FontStyle.normal,
735 ), 565 ),
736 textFontOptions: FontOptions( 566 textFontOptions: FontOptions(
737 fontFamily: "Main", 567 fontFamily: "Main",
738 - fontWeight: style?.fontWeight ?? FontWeight.normal, 568 + fontWeight: config.style?.fontWeight ?? FontWeight.normal,
739 fontShape: FontStyle.normal, 569 fontShape: FontStyle.normal,
740 ), 570 ),
741 style: MathStyle.display, 571 style: MathStyle.display,
@@ -743,7 +573,7 @@ class LatexMath extends InlineMd { @@ -743,7 +573,7 @@ class LatexMath extends InlineMd {
743 onErrorFallback: (err) { 573 onErrorFallback: (err) {
744 return Text( 574 return Text(
745 workaround(mathText), 575 workaround(mathText),
746 - textDirection: textDirection, 576 + textDirection: config.textDirection,
747 style: textStyle.copyWith( 577 style: textStyle.copyWith(
748 color: (!kDebugMode) 578 color: (!kDebugMode)
749 ? null 579 ? null
@@ -754,8 +584,8 @@ class LatexMath extends InlineMd { @@ -754,8 +584,8 @@ class LatexMath extends InlineMd {
754 return WidgetSpan( 584 return WidgetSpan(
755 alignment: PlaceholderAlignment.baseline, 585 alignment: PlaceholderAlignment.baseline,
756 baseline: TextBaseline.alphabetic, 586 baseline: TextBaseline.alphabetic,
757 - child: builder(  
758 - context, workaround(mathText), style ?? const TextStyle(), true), 587 + child: builder(context, workaround(mathText),
  588 + config.style ?? const TextStyle(), true),
759 ); 589 );
760 } 590 }
761 } 591 }
@@ -769,29 +599,19 @@ class ItalicMd extends InlineMd { @@ -769,29 +599,19 @@ class ItalicMd extends InlineMd {
769 InlineSpan span( 599 InlineSpan span(
770 BuildContext context, 600 BuildContext context,
771 String text, 601 String text,
772 - TextStyle? style,  
773 - TextDirection textDirection,  
774 - final void Function(String url, String title)? onLinkTab,  
775 - final String Function(String tex)? latexWorkaround,  
776 - final Widget Function(  
777 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
778 - latexBuilder,  
779 - final Widget Function(BuildContext context, String name, String code)?  
780 - codeBuilder, 602 + final GptMarkdownConfig config,
781 ) { 603 ) {
782 var match = exp.firstMatch(text.trim()); 604 var match = exp.firstMatch(text.trim());
  605 + var conf = config.copyWith(
  606 + style: (config.style ?? const TextStyle())
  607 + .copyWith(fontStyle: FontStyle.italic));
783 return TextSpan( 608 return TextSpan(
784 children: MarkdownComponent.generate( 609 children: MarkdownComponent.generate(
785 context, 610 context,
786 "${match?[1]}", 611 "${match?[1]}",
787 - (style ?? const TextStyle()).copyWith(fontStyle: FontStyle.italic),  
788 - textDirection,  
789 - onLinkTab,  
790 - latexWorkaround,  
791 - latexBuilder,  
792 - codeBuilder, 612 + conf,
793 ), 613 ),
794 - style: (style ?? const TextStyle()).copyWith(fontStyle: FontStyle.italic), 614 + style: conf.style,
795 ); 615 );
796 } 616 }
797 } 617 }
@@ -805,15 +625,7 @@ class SourceTag extends InlineMd { @@ -805,15 +625,7 @@ class SourceTag extends InlineMd {
805 InlineSpan span( 625 InlineSpan span(
806 BuildContext context, 626 BuildContext context,
807 String text, 627 String text,
808 - TextStyle? style,  
809 - TextDirection textDirection,  
810 - final void Function(String url, String title)? onLinkTab,  
811 - final String Function(String tex)? latexWorkaround,  
812 - final Widget Function(  
813 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
814 - latexBuilder,  
815 - final Widget Function(BuildContext context, String name, String code)?  
816 - codeBuilder, 628 + final GptMarkdownConfig config,
817 ) { 629 ) {
818 var match = exp.firstMatch(text.trim()); 630 var match = exp.firstMatch(text.trim());
819 if (match?[1] == null) { 631 if (match?[1] == null) {
@@ -835,7 +647,7 @@ class SourceTag extends InlineMd { @@ -835,7 +647,7 @@ class SourceTag extends InlineMd {
835 child: Text( 647 child: Text(
836 "${match?[1]}", 648 "${match?[1]}",
837 // style: (style ?? const TextStyle()).copyWith(), 649 // style: (style ?? const TextStyle()).copyWith(),
838 - textDirection: textDirection, 650 + textDirection: config.textDirection,
839 ), 651 ),
840 ), 652 ),
841 ), 653 ),
@@ -854,15 +666,7 @@ class ATagMd extends InlineMd { @@ -854,15 +666,7 @@ class ATagMd extends InlineMd {
854 InlineSpan span( 666 InlineSpan span(
855 BuildContext context, 667 BuildContext context,
856 String text, 668 String text,
857 - TextStyle? style,  
858 - TextDirection textDirection,  
859 - final void Function(String url, String title)? onLinkTab,  
860 - final String Function(String tex)? latexWorkaround,  
861 - final Widget Function(  
862 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
863 - latexBuilder,  
864 - final Widget Function(BuildContext context, String name, String code)?  
865 - codeBuilder, 669 + final GptMarkdownConfig config,
866 ) { 670 ) {
867 var match = exp.firstMatch(text.trim()); 671 var match = exp.firstMatch(text.trim());
868 if (match?[1] == null && match?[2] == null) { 672 if (match?[1] == null && match?[2] == null) {
@@ -873,21 +677,18 @@ class ATagMd extends InlineMd { @@ -873,21 +677,18 @@ class ATagMd extends InlineMd {
873 baseline: TextBaseline.alphabetic, 677 baseline: TextBaseline.alphabetic,
874 child: GestureDetector( 678 child: GestureDetector(
875 onTap: () { 679 onTap: () {
876 - if (onLinkTab == null) {  
877 - return;  
878 - }  
879 - onLinkTab("${match?[2]}", "${match?[1]}"); 680 + config.onLinkTab?.call("${match?[2]}", "${match?[1]}");
880 }, 681 },
881 child: Text.rich( 682 child: Text.rich(
882 TextSpan( 683 TextSpan(
883 text: "${match?[1]}", 684 text: "${match?[1]}",
884 - style: (style ?? const TextStyle()).copyWith( 685 + style: (config.style ?? const TextStyle()).copyWith(
885 color: Colors.blueAccent, 686 color: Colors.blueAccent,
886 decorationColor: Colors.blue, 687 decorationColor: Colors.blue,
887 decoration: TextDecoration.underline, 688 decoration: TextDecoration.underline,
888 ), 689 ),
889 ), 690 ),
890 - textDirection: textDirection, 691 + textDirection: config.textDirection,
891 ), 692 ),
892 ), 693 ),
893 ); 694 );
@@ -903,15 +704,7 @@ class ImageMd extends InlineMd { @@ -903,15 +704,7 @@ class ImageMd extends InlineMd {
903 InlineSpan span( 704 InlineSpan span(
904 BuildContext context, 705 BuildContext context,
905 String text, 706 String text,
906 - TextStyle? style,  
907 - TextDirection textDirection,  
908 - final void Function(String url, String title)? onLinkTab,  
909 - final String Function(String tex)? latexWorkaround,  
910 - final Widget Function(  
911 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
912 - latexBuilder,  
913 - final Widget Function(BuildContext context, String name, String code)?  
914 - codeBuilder, 707 + final GptMarkdownConfig config,
915 ) { 708 ) {
916 var match = exp.firstMatch(text.trim()); 709 var match = exp.firstMatch(text.trim());
917 double? height; 710 double? height;
@@ -959,15 +752,7 @@ class TableMd extends BlockMd { @@ -959,15 +752,7 @@ class TableMd extends BlockMd {
959 Widget build( 752 Widget build(
960 BuildContext context, 753 BuildContext context,
961 String text, 754 String text,
962 - TextStyle? style,  
963 - TextDirection textDirection,  
964 - void Function(String url, String title)? onLinkTab,  
965 - final String Function(String tex)? latexWorkaround,  
966 - final Widget Function(  
967 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
968 - latexBuilder,  
969 - final Widget Function(BuildContext context, String name, String code)?  
970 - codeBuilder, 755 + final GptMarkdownConfig config,
971 ) { 756 ) {
972 final List<Map<int, String>> value = text 757 final List<Map<int, String>> value = text
973 .split('\n') 758 .split('\n')
@@ -990,7 +775,7 @@ class TableMd extends BlockMd { @@ -990,7 +775,7 @@ class TableMd extends BlockMd {
990 } 775 }
991 } 776 }
992 if (maxCol == 0) { 777 if (maxCol == 0) {
993 - return Text("", style: style); 778 + return Text("", style: config.style);
994 } 779 }
995 final controller = ScrollController(); 780 final controller = ScrollController();
996 return Scrollbar( 781 return Scrollbar(
@@ -999,7 +784,7 @@ class TableMd extends BlockMd { @@ -999,7 +784,7 @@ class TableMd extends BlockMd {
999 controller: controller, 784 controller: controller,
1000 scrollDirection: Axis.horizontal, 785 scrollDirection: Axis.horizontal,
1001 child: Table( 786 child: Table(
1002 - textDirection: textDirection, 787 + textDirection: config.textDirection,
1003 defaultColumnWidth: CustomTableColumnWidth(), 788 defaultColumnWidth: CustomTableColumnWidth(),
1004 defaultVerticalAlignment: TableCellVerticalAlignment.middle, 789 defaultVerticalAlignment: TableCellVerticalAlignment.middle,
1005 border: TableBorder.all( 790 border: TableBorder.all(
@@ -1036,12 +821,7 @@ class TableMd extends BlockMd { @@ -1036,12 +821,7 @@ class TableMd extends BlockMd {
1036 horizontal: 8, vertical: 4), 821 horizontal: 8, vertical: 4),
1037 child: MdWidget( 822 child: MdWidget(
1038 (e[index] ?? "").trim(), 823 (e[index] ?? "").trim(),
1039 - textDirection: textDirection,  
1040 - onLinkTab: onLinkTab,  
1041 - style: style,  
1042 - latexWorkaround: latexWorkaround,  
1043 - latexBuilder: latexBuilder,  
1044 - codeBuilder: codeBuilder, 824 + config: config,
1045 ), 825 ),
1046 ), 826 ),
1047 ); 827 );
@@ -1072,23 +852,15 @@ class CodeBlockMd extends BlockMd { @@ -1072,23 +852,15 @@ class CodeBlockMd extends BlockMd {
1072 Widget build( 852 Widget build(
1073 BuildContext context, 853 BuildContext context,
1074 String text, 854 String text,
1075 - TextStyle? style,  
1076 - TextDirection textDirection,  
1077 - final void Function(String url, String title)? onLinkTab,  
1078 - final String Function(String tex)? latexWorkaround,  
1079 - final Widget Function(  
1080 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
1081 - latexBuilder,  
1082 - final Widget Function(BuildContext context, String name, String code)?  
1083 - codeBuilder, 855 + final GptMarkdownConfig config,
1084 ) { 856 ) {
1085 String codes = exp.firstMatch(text)?[2] ?? ""; 857 String codes = exp.firstMatch(text)?[2] ?? "";
1086 String name = exp.firstMatch(text)?[1] ?? ""; 858 String name = exp.firstMatch(text)?[1] ?? "";
1087 codes = codes.replaceAll(r"```", "").trim(); 859 codes = codes.replaceAll(r"```", "").trim();
1088 return Padding( 860 return Padding(
1089 padding: const EdgeInsets.all(16.0), 861 padding: const EdgeInsets.all(16.0),
1090 - child: codeBuilder != null  
1091 - ? codeBuilder(context, name, codes) 862 + child: config.codeBuilder != null
  863 + ? config.codeBuilder?.call(context, name, codes)
1092 : CodeField(name: name, codes: codes), 864 : CodeField(name: name, codes: codes),
1093 ); 865 );
1094 } 866 }
1 import 'dart:math'; 1 import 'dart:math';
2 2
3 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
  4 +import 'package:gpt_markdown/custom_widgets/markdow_config.dart';
4 import 'package:gpt_markdown/markdown_component.dart'; 5 import 'package:gpt_markdown/markdown_component.dart';
5 6
6 /// It creates a markdown widget closed to each other. 7 /// It creates a markdown widget closed to each other.
@@ -8,31 +9,10 @@ class MdWidget extends StatelessWidget { @@ -8,31 +9,10 @@ class MdWidget extends StatelessWidget {
8 const MdWidget( 9 const MdWidget(
9 this.exp, { 10 this.exp, {
10 super.key, 11 super.key,
11 - this.style,  
12 - this.textDirection = TextDirection.ltr,  
13 - this.onLinkTab,  
14 - this.textAlign,  
15 - this.textScaler,  
16 - this.latexWorkaround,  
17 - this.latexBuilder,  
18 - this.followLinkColor = false,  
19 - this.codeBuilder,  
20 - this.maxLines, 12 + required this.config,
21 }); 13 });
22 final String exp; 14 final String exp;
23 - final TextDirection textDirection;  
24 - final TextStyle? style;  
25 - final TextAlign? textAlign;  
26 - final TextScaler? textScaler;  
27 - final void Function(String url, String title)? onLinkTab;  
28 - final String Function(String tex)? latexWorkaround;  
29 - final Widget Function(  
30 - BuildContext context, String tex, TextStyle textStyle, bool inline)?  
31 - latexBuilder;  
32 - final bool followLinkColor;  
33 - final Widget Function(BuildContext context, String name, String code)?  
34 - codeBuilder;  
35 - final int? maxLines; 15 + final GptMarkdownConfig config;
36 16
37 @override 17 @override
38 Widget build(BuildContext context) { 18 Widget build(BuildContext context) {
@@ -50,23 +30,19 @@ class MdWidget extends StatelessWidget { @@ -50,23 +30,19 @@ class MdWidget extends StatelessWidget {
50 String body = (match[1] ?? match[2])?.replaceAll("\n", " ") ?? ""; 30 String body = (match[1] ?? match[2])?.replaceAll("\n", " ") ?? "";
51 return "\\[$body\\]"; 31 return "\\[$body\\]";
52 }), 32 }),
53 - style,  
54 - textDirection,  
55 - onLinkTab,  
56 - latexWorkaround,  
57 - latexBuilder,  
58 - codeBuilder, 33 + config,
59 ), 34 ),
60 ); 35 );
61 return Text.rich( 36 return Text.rich(
62 TextSpan( 37 TextSpan(
63 children: list, 38 children: list,
64 - style: style?.copyWith(), 39 + style: config.style?.copyWith(),
65 ), 40 ),
66 - textDirection: textDirection,  
67 - textScaler: textScaler,  
68 - textAlign: textAlign,  
69 - maxLines: maxLines, 41 + textDirection: config.textDirection,
  42 + textScaler: config.textScaler,
  43 + textAlign: config.textAlign,
  44 + maxLines: config.maxLines,
  45 + overflow: config.overflow,
70 ); 46 );
71 } 47 }
72 } 48 }
1 name: gpt_markdown 1 name: gpt_markdown
2 description: "The purpose of this package is to render the response of ChatGPT into a Flutter app." 2 description: "The purpose of this package is to render the response of ChatGPT into a Flutter app."
3 -version: 0.1.5 3 +version: 0.1.6
4 homepage: https://github.com/saminsohag/flutter_packages/tree/main/gpt_markdown 4 homepage: https://github.com/saminsohag/flutter_packages/tree/main/gpt_markdown
5 5
6 environment: 6 environment: