Samin yeasar Sohag
Committed by GitHub

Merge pull request #7 from suysoftware/main

add CodeBuilder feature
@@ -67,6 +67,21 @@ Welcome to ChatGPT! Below is an example of a response with Markdown and LaTeX co @@ -67,6 +67,21 @@ Welcome to ChatGPT! Below is an example of a response with Markdown and LaTeX co
67 67
68 ### Markdown Example 68 ### Markdown Example
69 69
  70 +
  71 +```
  72 +class MarkdownHelper {
  73 +
  74 +
  75 + Map<String, Widget> getTitleWidget(m.Node node) => title.getTitleWidget(node);
  76 +
  77 + Widget getPWidget(m.Element node) => p.getPWidget(node);
  78 +
  79 + Widget getPreWidget(m.Node node) => pre.getPreWidget(node);
  80 +
  81 +}
  82 +```
  83 +
  84 +
70 You can use Markdown to format text easily. Here are some examples: 85 You can use Markdown to format text easily. Here are some examples:
71 86
72 - **Bold Text**: **This text is bold** 87 - **Bold Text**: **This text is bold**
@@ -259,7 +259,7 @@ @@ -259,7 +259,7 @@
259 isa = PBXProject; 259 isa = PBXProject;
260 attributes = { 260 attributes = {
261 LastSwiftUpdateCheck = 0920; 261 LastSwiftUpdateCheck = 0920;
262 - LastUpgradeCheck = 1510; 262 + LastUpgradeCheck = 1430;
263 ORGANIZATIONNAME = ""; 263 ORGANIZATIONNAME = "";
264 TargetAttributes = { 264 TargetAttributes = {
265 331C80D4294CF70F00263BE5 = { 265 331C80D4294CF70F00263BE5 = {
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <Scheme 2 <Scheme
3 - LastUpgradeVersion = "1510" 3 + LastUpgradeVersion = "1430"
4 version = "1.3"> 4 version = "1.3">
5 <BuildAction 5 <BuildAction
6 parallelizeBuildables = "YES" 6 parallelizeBuildables = "YES"
@@ -215,30 +215,6 @@ packages: @@ -215,30 +215,6 @@ packages:
215 url: "https://pub.dev" 215 url: "https://pub.dev"
216 source: hosted 216 source: hosted
217 version: "0.6.7" 217 version: "0.6.7"
218 - leak_tracker:  
219 - dependency: transitive  
220 - description:  
221 - name: leak_tracker  
222 - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"  
223 - url: "https://pub.dev"  
224 - source: hosted  
225 - version: "10.0.0"  
226 - leak_tracker_flutter_testing:  
227 - dependency: transitive  
228 - description:  
229 - name: leak_tracker_flutter_testing  
230 - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0  
231 - url: "https://pub.dev"  
232 - source: hosted  
233 - version: "2.0.1"  
234 - leak_tracker_testing:  
235 - dependency: transitive  
236 - description:  
237 - name: leak_tracker_testing  
238 - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47  
239 - url: "https://pub.dev"  
240 - source: hosted  
241 - version: "2.0.1"  
242 lints: 218 lints:
243 dependency: transitive 219 dependency: transitive
244 description: 220 description:
@@ -251,26 +227,26 @@ packages: @@ -251,26 +227,26 @@ packages:
251 dependency: transitive 227 dependency: transitive
252 description: 228 description:
253 name: matcher 229 name: matcher
254 - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb 230 + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
255 url: "https://pub.dev" 231 url: "https://pub.dev"
256 source: hosted 232 source: hosted
257 - version: "0.12.16+1" 233 + version: "0.12.16"
258 material_color_utilities: 234 material_color_utilities:
259 dependency: transitive 235 dependency: transitive
260 description: 236 description:
261 name: material_color_utilities 237 name: material_color_utilities
262 - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" 238 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
263 url: "https://pub.dev" 239 url: "https://pub.dev"
264 source: hosted 240 source: hosted
265 - version: "0.8.0" 241 + version: "0.5.0"
266 meta: 242 meta:
267 dependency: transitive 243 dependency: transitive
268 description: 244 description:
269 name: meta 245 name: meta
270 - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 246 + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
271 url: "https://pub.dev" 247 url: "https://pub.dev"
272 source: hosted 248 source: hosted
273 - version: "1.11.0" 249 + version: "1.10.0"
274 nested: 250 nested:
275 dependency: transitive 251 dependency: transitive
276 description: 252 description:
@@ -283,10 +259,10 @@ packages: @@ -283,10 +259,10 @@ packages:
283 dependency: transitive 259 dependency: transitive
284 description: 260 description:
285 name: path 261 name: path
286 - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" 262 + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
287 url: "https://pub.dev" 263 url: "https://pub.dev"
288 source: hosted 264 source: hosted
289 - version: "1.9.0" 265 + version: "1.8.3"
290 path_parsing: 266 path_parsing:
291 dependency: transitive 267 dependency: transitive
292 description: 268 description:
@@ -612,14 +588,6 @@ packages: @@ -612,14 +588,6 @@ packages:
612 url: "https://pub.dev" 588 url: "https://pub.dev"
613 source: hosted 589 source: hosted
614 version: "2.1.4" 590 version: "2.1.4"
615 - vm_service:  
616 - dependency: transitive  
617 - description:  
618 - name: vm_service  
619 - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957  
620 - url: "https://pub.dev"  
621 - source: hosted  
622 - version: "13.0.0"  
623 web: 591 web:
624 dependency: transitive 592 dependency: transitive
625 description: 593 description:
@@ -17,6 +17,7 @@ class TexMarkdown extends StatelessWidget { @@ -17,6 +17,7 @@ class TexMarkdown extends StatelessWidget {
17 this.textScaleFactor, 17 this.textScaleFactor,
18 this.onLinkTab, 18 this.onLinkTab,
19 this.latexBuilder, 19 this.latexBuilder,
  20 + this.codeBuilder,
20 }); 21 });
21 final TextDirection textDirection; 22 final TextDirection textDirection;
22 final String data; 23 final String data;
@@ -27,6 +28,7 @@ class TexMarkdown extends StatelessWidget { @@ -27,6 +28,7 @@ class TexMarkdown extends StatelessWidget {
27 final String Function(String tex)? latexWorkaround; 28 final String Function(String tex)? latexWorkaround;
28 final Widget Function(BuildContext context, String tex)? latexBuilder; 29 final Widget Function(BuildContext context, String tex)? latexBuilder;
29 final bool followLinkColor; 30 final bool followLinkColor;
  31 + final Widget Function(BuildContext context, String tex)? codeBuilder;
30 32
31 @override 33 @override
32 Widget build(BuildContext context) { 34 Widget build(BuildContext context) {
@@ -62,6 +64,7 @@ class TexMarkdown extends StatelessWidget { @@ -62,6 +64,7 @@ class TexMarkdown extends StatelessWidget {
62 followLinkColor: followLinkColor, 64 followLinkColor: followLinkColor,
63 latexWorkaround: latexWorkaround, 65 latexWorkaround: latexWorkaround,
64 latexBuilder: latexBuilder, 66 latexBuilder: latexBuilder,
  67 + codeBuilder: codeBuilder,
65 )); 68 ));
66 } 69 }
67 } 70 }
@@ -38,10 +38,10 @@ abstract class MarkdownComponent { @@ -38,10 +38,10 @@ abstract class MarkdownComponent {
38 final void Function(String url, String title)? onLinkTab, 38 final void Function(String url, String title)? onLinkTab,
39 final String Function(String tex)? latexWorkaround, 39 final String Function(String tex)? latexWorkaround,
40 final Widget Function(BuildContext context, String tex)? latexBuilder, 40 final Widget Function(BuildContext context, String tex)? latexBuilder,
  41 + final Widget Function(BuildContext context, String tex)? codeBuilder,
41 ) { 42 ) {
42 List<InlineSpan> spans = []; 43 List<InlineSpan> spans = [];
43 - List<String> regexes =  
44 - components.map<String>((e) => e.exp.pattern).toList(); 44 + List<String> regexes = components.map<String>((e) => e.exp.pattern).toList();
45 final combinedRegex = RegExp( 45 final combinedRegex = RegExp(
46 regexes.join("|"), 46 regexes.join("|"),
47 multiLine: true, 47 multiLine: true,
@@ -64,6 +64,7 @@ abstract class MarkdownComponent { @@ -64,6 +64,7 @@ abstract class MarkdownComponent {
64 onLinkTab, 64 onLinkTab,
65 latexWorkaround, 65 latexWorkaround,
66 latexBuilder, 66 latexBuilder,
  67 + codeBuilder,
67 )); 68 ));
68 } else { 69 } else {
69 if (each is BlockMd) { 70 if (each is BlockMd) {
@@ -84,6 +85,7 @@ abstract class MarkdownComponent { @@ -84,6 +85,7 @@ abstract class MarkdownComponent {
84 onLinkTab, 85 onLinkTab,
85 latexWorkaround, 86 latexWorkaround,
86 latexBuilder, 87 latexBuilder,
  88 + codeBuilder,
87 ), 89 ),
88 TextSpan( 90 TextSpan(
89 text: "\n ", 91 text: "\n ",
@@ -123,6 +125,7 @@ abstract class MarkdownComponent { @@ -123,6 +125,7 @@ abstract class MarkdownComponent {
123 final void Function(String url, String title)? onLinkTab, 125 final void Function(String url, String title)? onLinkTab,
124 final String Function(String tex)? latexWorkaround, 126 final String Function(String tex)? latexWorkaround,
125 final Widget Function(BuildContext context, String tex)? latexBuilder, 127 final Widget Function(BuildContext context, String tex)? latexBuilder,
  128 + final Widget Function(BuildContext context, String tex)? codeBuilder,
126 ); 129 );
127 130
128 RegExp get exp; 131 RegExp get exp;
@@ -143,6 +146,7 @@ abstract class InlineMd extends MarkdownComponent { @@ -143,6 +146,7 @@ abstract class InlineMd extends MarkdownComponent {
143 final void Function(String url, String title)? onLinkTab, 146 final void Function(String url, String title)? onLinkTab,
144 final String Function(String tex)? latexWorkaround, 147 final String Function(String tex)? latexWorkaround,
145 final Widget Function(BuildContext context, String tex)? latexBuilder, 148 final Widget Function(BuildContext context, String tex)? latexBuilder,
  149 + final Widget Function(BuildContext context, String tex)? codeBuilder,
146 ); 150 );
147 } 151 }
148 152
@@ -159,6 +163,7 @@ abstract class BlockMd extends MarkdownComponent { @@ -159,6 +163,7 @@ abstract class BlockMd extends MarkdownComponent {
159 final void Function(String url, String title)? onLinkTab, 163 final void Function(String url, String title)? onLinkTab,
160 final String Function(String tex)? latexWorkaround, 164 final String Function(String tex)? latexWorkaround,
161 final Widget Function(BuildContext context, String tex)? latexBuilder, 165 final Widget Function(BuildContext context, String tex)? latexBuilder,
  166 + final Widget Function(BuildContext context, String tex)? codeBuilder,
162 ) { 167 ) {
163 return WidgetSpan( 168 return WidgetSpan(
164 child: build( 169 child: build(
@@ -169,6 +174,7 @@ abstract class BlockMd extends MarkdownComponent { @@ -169,6 +174,7 @@ abstract class BlockMd extends MarkdownComponent {
169 onLinkTab, 174 onLinkTab,
170 latexWorkaround, 175 latexWorkaround,
171 latexBuilder, 176 latexBuilder,
  177 + codeBuilder,
172 ), 178 ),
173 alignment: PlaceholderAlignment.middle, 179 alignment: PlaceholderAlignment.middle,
174 ); 180 );
@@ -182,6 +188,7 @@ abstract class BlockMd extends MarkdownComponent { @@ -182,6 +188,7 @@ abstract class BlockMd extends MarkdownComponent {
182 final void Function(String url, String title)? onLinkTab, 188 final void Function(String url, String title)? onLinkTab,
183 final String Function(String tex)? latexWorkaround, 189 final String Function(String tex)? latexWorkaround,
184 final Widget Function(BuildContext context, String tex)? latexBuilder, 190 final Widget Function(BuildContext context, String tex)? latexBuilder,
  191 + final Widget Function(BuildContext context, String tex)? codeBuilder,
185 ); 192 );
186 } 193 }
187 194
@@ -198,6 +205,7 @@ class HTag extends BlockMd { @@ -198,6 +205,7 @@ class HTag extends BlockMd {
198 final void Function(String url, String title)? onLinkTab, 205 final void Function(String url, String title)? onLinkTab,
199 final String Function(String tex)? latexWorkaround, 206 final String Function(String tex)? latexWorkaround,
200 final Widget Function(BuildContext context, String tex)? latexBuilder, 207 final Widget Function(BuildContext context, String tex)? latexBuilder,
  208 + final Widget Function(BuildContext context, String tex)? codeBuilder,
201 ) { 209 ) {
202 var match = exp.firstMatch(text.trim()); 210 var match = exp.firstMatch(text.trim());
203 return Text.rich( 211 return Text.rich(
@@ -207,35 +215,18 @@ class HTag extends BlockMd { @@ -207,35 +215,18 @@ class HTag extends BlockMd {
207 context, 215 context,
208 "${match?[2]}", 216 "${match?[2]}",
209 [ 217 [
210 - Theme.of(context)  
211 - .textTheme  
212 - .headlineLarge  
213 - ?.copyWith(color: style?.color),  
214 - Theme.of(context)  
215 - .textTheme  
216 - .headlineMedium  
217 - ?.copyWith(color: style?.color),  
218 - Theme.of(context)  
219 - .textTheme  
220 - .headlineSmall  
221 - ?.copyWith(color: style?.color),  
222 - Theme.of(context)  
223 - .textTheme  
224 - .titleLarge  
225 - ?.copyWith(color: style?.color),  
226 - Theme.of(context)  
227 - .textTheme  
228 - .titleMedium  
229 - ?.copyWith(color: style?.color),  
230 - Theme.of(context)  
231 - .textTheme  
232 - .titleSmall  
233 - ?.copyWith(color: style?.color), 218 + Theme.of(context).textTheme.headlineLarge?.copyWith(color: style?.color),
  219 + Theme.of(context).textTheme.headlineMedium?.copyWith(color: style?.color),
  220 + Theme.of(context).textTheme.headlineSmall?.copyWith(color: style?.color),
  221 + Theme.of(context).textTheme.titleLarge?.copyWith(color: style?.color),
  222 + Theme.of(context).textTheme.titleMedium?.copyWith(color: style?.color),
  223 + Theme.of(context).textTheme.titleSmall?.copyWith(color: style?.color),
234 ][match![1]!.length - 1], 224 ][match![1]!.length - 1],
235 textDirection, 225 textDirection,
236 (url, title) {}, 226 (url, title) {},
237 latexWorkaround, 227 latexWorkaround,
238 latexBuilder, 228 latexBuilder,
  229 + codeBuilder,
239 )), 230 )),
240 if (match[1]!.length == 1) ...[ 231 if (match[1]!.length == 1) ...[
241 const TextSpan( 232 const TextSpan(
@@ -268,6 +259,7 @@ class NewLines extends InlineMd { @@ -268,6 +259,7 @@ class NewLines extends InlineMd {
268 final void Function(String url, String title)? onLinkTab, 259 final void Function(String url, String title)? onLinkTab,
269 final String Function(String tex)? latexWorkaround, 260 final String Function(String tex)? latexWorkaround,
270 final Widget Function(BuildContext context, String tex)? latexBuilder, 261 final Widget Function(BuildContext context, String tex)? latexBuilder,
  262 + final Widget Function(BuildContext context, String tex)? codeBuilder,
271 ) { 263 ) {
272 return TextSpan( 264 return TextSpan(
273 text: "\n\n\n\n", 265 text: "\n\n\n\n",
@@ -292,6 +284,7 @@ class HrLine extends BlockMd { @@ -292,6 +284,7 @@ class HrLine extends BlockMd {
292 final void Function(String url, String title)? onLinkTab, 284 final void Function(String url, String title)? onLinkTab,
293 final String Function(String tex)? latexWorkaround, 285 final String Function(String tex)? latexWorkaround,
294 final Widget Function(BuildContext context, String tex)? latexBuilder, 286 final Widget Function(BuildContext context, String tex)? latexBuilder,
  287 + final Widget Function(BuildContext context, String tex)? codeBuilder,
295 ) { 288 ) {
296 return CustomDivider( 289 return CustomDivider(
297 height: 2, 290 height: 2,
@@ -315,6 +308,7 @@ class CheckBoxMd extends BlockMd { @@ -315,6 +308,7 @@ class CheckBoxMd extends BlockMd {
315 final void Function(String url, String title)? onLinkTab, 308 final void Function(String url, String title)? onLinkTab,
316 final String Function(String tex)? latexWorkaround, 309 final String Function(String tex)? latexWorkaround,
317 final Widget Function(BuildContext context, String tex)? latexBuilder, 310 final Widget Function(BuildContext context, String tex)? latexBuilder,
  311 + final Widget Function(BuildContext context, String tex)? codeBuilder,
318 ) { 312 ) {
319 var match = exp.firstMatch(text.trim()); 313 var match = exp.firstMatch(text.trim());
320 return CustomCb( 314 return CustomCb(
@@ -347,6 +341,7 @@ class RadioButtonMd extends BlockMd { @@ -347,6 +341,7 @@ class RadioButtonMd extends BlockMd {
347 final void Function(String url, String title)? onLinkTab, 341 final void Function(String url, String title)? onLinkTab,
348 final String Function(String tex)? latexWorkaround, 342 final String Function(String tex)? latexWorkaround,
349 final Widget Function(BuildContext context, String tex)? latexBuilder, 343 final Widget Function(BuildContext context, String tex)? latexBuilder,
  344 + final Widget Function(BuildContext context, String tex)? codeBuilder,
350 ) { 345 ) {
351 var match = exp.firstMatch(text.trim()); 346 var match = exp.firstMatch(text.trim());
352 return CustomRb( 347 return CustomRb(
@@ -379,6 +374,7 @@ class IndentMd extends BlockMd { @@ -379,6 +374,7 @@ class IndentMd extends BlockMd {
379 final void Function(String url, String title)? onLinkTab, 374 final void Function(String url, String title)? onLinkTab,
380 final String Function(String tex)? latexWorkaround, 375 final String Function(String tex)? latexWorkaround,
381 final Widget Function(BuildContext context, String tex)? latexBuilder, 376 final Widget Function(BuildContext context, String tex)? latexBuilder,
  377 + final Widget Function(BuildContext context, String tex)? codeBuilder,
382 ) { 378 ) {
383 [ 379 [
384 r"\\\[(.*?)\\\]", 380 r"\\\[(.*?)\\\]",
@@ -394,8 +390,7 @@ class IndentMd extends BlockMd { @@ -394,8 +390,7 @@ class IndentMd extends BlockMd {
394 textDirection: textDirection, 390 textDirection: textDirection,
395 child: RichText( 391 child: RichText(
396 text: TextSpan( 392 text: TextSpan(
397 - children: MarkdownComponent.generate(context, "${match?[2]}", style,  
398 - textDirection, onLinkTab, latexWorkaround, latexBuilder), 393 + children: MarkdownComponent.generate(context, "${match?[2]}", style, textDirection, onLinkTab, latexWorkaround, latexBuilder, codeBuilder),
399 )), 394 )),
400 ); 395 );
401 } 396 }
@@ -416,6 +411,7 @@ class UnOrderedList extends BlockMd { @@ -416,6 +411,7 @@ class UnOrderedList extends BlockMd {
416 final void Function(String url, String title)? onLinkTab, 411 final void Function(String url, String title)? onLinkTab,
417 final String Function(String tex)? latexWorkaround, 412 final String Function(String tex)? latexWorkaround,
418 final Widget Function(BuildContext context, String tex)? latexBuilder, 413 final Widget Function(BuildContext context, String tex)? latexBuilder,
  414 + final Widget Function(BuildContext context, String tex)? codeBuilder,
419 ) { 415 ) {
420 var match = exp.firstMatch(text); 416 var match = exp.firstMatch(text);
421 return UnorderedListView( 417 return UnorderedListView(
@@ -451,6 +447,7 @@ class OrderedList extends BlockMd { @@ -451,6 +447,7 @@ class OrderedList extends BlockMd {
451 final void Function(String url, String title)? onLinkTab, 447 final void Function(String url, String title)? onLinkTab,
452 final String Function(String tex)? latexWorkaround, 448 final String Function(String tex)? latexWorkaround,
453 final Widget Function(BuildContext context, String tex)? latexBuilder, 449 final Widget Function(BuildContext context, String tex)? latexBuilder,
  450 + final Widget Function(BuildContext context, String tex)? codeBuilder,
454 ) { 451 ) {
455 var match = exp.firstMatch(text.trim()); 452 var match = exp.firstMatch(text.trim());
456 return OrderedListView( 453 return OrderedListView(
@@ -482,6 +479,7 @@ class HighlightedText extends InlineMd { @@ -482,6 +479,7 @@ class HighlightedText extends InlineMd {
482 final void Function(String url, String title)? onLinkTab, 479 final void Function(String url, String title)? onLinkTab,
483 final String Function(String tex)? latexWorkaround, 480 final String Function(String tex)? latexWorkaround,
484 final Widget Function(BuildContext context, String tex)? latexBuilder, 481 final Widget Function(BuildContext context, String tex)? latexBuilder,
  482 + final Widget Function(BuildContext context, String tex)? codeBuilder,
485 ) { 483 ) {
486 return TextSpan( 484 return TextSpan(
487 text: text, 485 text: text,
@@ -517,21 +515,21 @@ class BoldMd extends InlineMd { @@ -517,21 +515,21 @@ class BoldMd extends InlineMd {
517 final void Function(String url, String title)? onLinkTab, 515 final void Function(String url, String title)? onLinkTab,
518 final String Function(String tex)? latexWorkaround, 516 final String Function(String tex)? latexWorkaround,
519 final Widget Function(BuildContext context, String tex)? latexBuilder, 517 final Widget Function(BuildContext context, String tex)? latexBuilder,
  518 + final Widget Function(BuildContext context, String tex)? codeBuilder,
520 ) { 519 ) {
521 var match = exp.firstMatch(text.trim()); 520 var match = exp.firstMatch(text.trim());
522 return TextSpan( 521 return TextSpan(
523 children: MarkdownComponent.generate( 522 children: MarkdownComponent.generate(
524 context, 523 context,
525 "${match?[1]}", 524 "${match?[1]}",
526 - style?.copyWith(fontWeight: FontWeight.bold) ??  
527 - const TextStyle(fontWeight: FontWeight.w900), 525 + style?.copyWith(fontWeight: FontWeight.bold) ?? const TextStyle(fontWeight: FontWeight.w900),
528 textDirection, 526 textDirection,
529 onLinkTab, 527 onLinkTab,
530 latexWorkaround, 528 latexWorkaround,
531 latexBuilder, 529 latexBuilder,
  530 + codeBuilder,
532 ), 531 ),
533 - style: style?.copyWith(fontWeight: FontWeight.bold) ??  
534 - const TextStyle(fontWeight: FontWeight.bold), 532 + style: style?.copyWith(fontWeight: FontWeight.bold) ?? const TextStyle(fontWeight: FontWeight.bold),
535 ); 533 );
536 } 534 }
537 } 535 }
@@ -552,6 +550,7 @@ class LatexMathMultyLine extends BlockMd { @@ -552,6 +550,7 @@ class LatexMathMultyLine extends BlockMd {
552 void Function(String url, String title)? onLinkTab, 550 void Function(String url, String title)? onLinkTab,
553 String Function(String tex)? latexWorkaround, 551 String Function(String tex)? latexWorkaround,
554 Widget Function(BuildContext context, String tex)? latexBuilder, 552 Widget Function(BuildContext context, String tex)? latexBuilder,
  553 + Widget Function(BuildContext context, String tex)? codeBuilder,
555 ) { 554 ) {
556 var p0 = exp.firstMatch(text.trim()); 555 var p0 = exp.firstMatch(text.trim());
557 p0?.group(0); 556 p0?.group(0);
@@ -572,8 +571,7 @@ class LatexMathMultyLine extends BlockMd { @@ -572,8 +571,7 @@ class LatexMathMultyLine extends BlockMd {
572 options: MathOptions( 571 options: MathOptions(
573 sizeUnderTextStyle: MathSize.large, 572 sizeUnderTextStyle: MathSize.large,
574 color: style?.color ?? Theme.of(context).colorScheme.onSurface, 573 color: style?.color ?? Theme.of(context).colorScheme.onSurface,
575 - fontSize: style?.fontSize ??  
576 - Theme.of(context).textTheme.bodyMedium?.fontSize, 574 + fontSize: style?.fontSize ?? Theme.of(context).textTheme.bodyMedium?.fontSize,
577 mathFontOptions: FontOptions( 575 mathFontOptions: FontOptions(
578 fontFamily: "Main", 576 fontFamily: "Main",
579 fontWeight: style?.fontWeight ?? FontWeight.normal, 577 fontWeight: style?.fontWeight ?? FontWeight.normal,
@@ -590,9 +588,7 @@ class LatexMathMultyLine extends BlockMd { @@ -590,9 +588,7 @@ class LatexMathMultyLine extends BlockMd {
590 return Text( 588 return Text(
591 workaround(mathText), 589 workaround(mathText),
592 textDirection: textDirection, 590 textDirection: textDirection,
593 - style: style?.copyWith(  
594 - color: Theme.of(context).colorScheme.error) ??  
595 - TextStyle(color: Theme.of(context).colorScheme.error), 591 + style: style?.copyWith(color: Theme.of(context).colorScheme.error) ?? TextStyle(color: Theme.of(context).colorScheme.error),
596 ); 592 );
597 }, 593 },
598 ); 594 );
@@ -620,6 +616,7 @@ class LatexMath extends InlineMd { @@ -620,6 +616,7 @@ class LatexMath extends InlineMd {
620 final void Function(String url, String title)? onLinkTab, 616 final void Function(String url, String title)? onLinkTab,
621 final String Function(String tex)? latexWorkaround, 617 final String Function(String tex)? latexWorkaround,
622 final Widget Function(BuildContext context, String tex)? latexBuilder, 618 final Widget Function(BuildContext context, String tex)? latexBuilder,
  619 + final Widget Function(BuildContext context, String tex)? codeBuilder,
623 ) { 620 ) {
624 var p0 = exp.firstMatch(text.trim()); 621 var p0 = exp.firstMatch(text.trim());
625 p0?.group(0); 622 p0?.group(0);
@@ -641,8 +638,7 @@ class LatexMath extends InlineMd { @@ -641,8 +638,7 @@ class LatexMath extends InlineMd {
641 options: MathOptions( 638 options: MathOptions(
642 sizeUnderTextStyle: MathSize.large, 639 sizeUnderTextStyle: MathSize.large,
643 color: style?.color ?? Theme.of(context).colorScheme.onSurface, 640 color: style?.color ?? Theme.of(context).colorScheme.onSurface,
644 - fontSize: style?.fontSize ??  
645 - Theme.of(context).textTheme.bodyMedium?.fontSize, 641 + fontSize: style?.fontSize ?? Theme.of(context).textTheme.bodyMedium?.fontSize,
646 mathFontOptions: FontOptions( 642 mathFontOptions: FontOptions(
647 fontFamily: "Main", 643 fontFamily: "Main",
648 fontWeight: style?.fontWeight ?? FontWeight.normal, 644 fontWeight: style?.fontWeight ?? FontWeight.normal,
@@ -659,9 +655,7 @@ class LatexMath extends InlineMd { @@ -659,9 +655,7 @@ class LatexMath extends InlineMd {
659 return Text( 655 return Text(
660 workaround(mathText), 656 workaround(mathText),
661 textDirection: textDirection, 657 textDirection: textDirection,
662 - style:  
663 - style?.copyWith(color: Theme.of(context).colorScheme.error) ??  
664 - TextStyle(color: Theme.of(context).colorScheme.error), 658 + style: style?.copyWith(color: Theme.of(context).colorScheme.error) ?? TextStyle(color: Theme.of(context).colorScheme.error),
665 ); 659 );
666 }, 660 },
667 ), 661 ),
@@ -683,6 +677,7 @@ class ItalicMd extends InlineMd { @@ -683,6 +677,7 @@ class ItalicMd extends InlineMd {
683 final void Function(String url, String title)? onLinkTab, 677 final void Function(String url, String title)? onLinkTab,
684 final String Function(String tex)? latexWorkaround, 678 final String Function(String tex)? latexWorkaround,
685 final Widget Function(BuildContext context, String tex)? latexBuilder, 679 final Widget Function(BuildContext context, String tex)? latexBuilder,
  680 + final Widget Function(BuildContext context, String tex)? codeBuilder,
686 ) { 681 ) {
687 var match = exp.firstMatch(text.trim()); 682 var match = exp.firstMatch(text.trim());
688 return TextSpan( 683 return TextSpan(
@@ -694,6 +689,7 @@ class ItalicMd extends InlineMd { @@ -694,6 +689,7 @@ class ItalicMd extends InlineMd {
694 onLinkTab, 689 onLinkTab,
695 latexWorkaround, 690 latexWorkaround,
696 latexBuilder, 691 latexBuilder,
  692 + codeBuilder,
697 ), 693 ),
698 style: (style ?? const TextStyle()).copyWith(fontStyle: FontStyle.italic), 694 style: (style ?? const TextStyle()).copyWith(fontStyle: FontStyle.italic),
699 ); 695 );
@@ -714,6 +710,7 @@ class ATagMd extends InlineMd { @@ -714,6 +710,7 @@ class ATagMd extends InlineMd {
714 final void Function(String url, String title)? onLinkTab, 710 final void Function(String url, String title)? onLinkTab,
715 final String Function(String tex)? latexWorkaround, 711 final String Function(String tex)? latexWorkaround,
716 final Widget Function(BuildContext context, String tex)? latexBuilder, 712 final Widget Function(BuildContext context, String tex)? latexBuilder,
  713 + final Widget Function(BuildContext context, String tex)? codeBuilder,
717 ) { 714 ) {
718 var match = exp.firstMatch(text.trim()); 715 var match = exp.firstMatch(text.trim());
719 if (match?[1] == null && match?[2] == null) { 716 if (match?[1] == null && match?[2] == null) {
@@ -759,13 +756,13 @@ class ImageMd extends InlineMd { @@ -759,13 +756,13 @@ class ImageMd extends InlineMd {
759 final void Function(String url, String title)? onLinkTab, 756 final void Function(String url, String title)? onLinkTab,
760 final String Function(String tex)? latexWorkaround, 757 final String Function(String tex)? latexWorkaround,
761 final Widget Function(BuildContext context, String tex)? latexBuilder, 758 final Widget Function(BuildContext context, String tex)? latexBuilder,
  759 + final Widget Function(BuildContext context, String tex)? codeBuilder,
762 ) { 760 ) {
763 var match = exp.firstMatch(text.trim()); 761 var match = exp.firstMatch(text.trim());
764 double? height; 762 double? height;
765 double? width; 763 double? width;
766 if (match?[1] != null) { 764 if (match?[1] != null) {
767 - var size = RegExp(r"^([0-9]+)?x?([0-9]+)?")  
768 - .firstMatch(match![1].toString().trim()); 765 + var size = RegExp(r"^([0-9]+)?x?([0-9]+)?").firstMatch(match![1].toString().trim());
769 width = double.tryParse(size?[1]?.toString().trim() ?? 'a'); 766 width = double.tryParse(size?[1]?.toString().trim() ?? 'a');
770 height = double.tryParse(size?[2]?.toString().trim() ?? 'a'); 767 height = double.tryParse(size?[2]?.toString().trim() ?? 'a');
771 } 768 }
@@ -778,16 +775,12 @@ class ImageMd extends InlineMd { @@ -778,16 +775,12 @@ class ImageMd extends InlineMd {
778 image: NetworkImage( 775 image: NetworkImage(
779 "${match?[2]}", 776 "${match?[2]}",
780 ), 777 ),
781 - loadingBuilder: (BuildContext context, Widget child,  
782 - ImageChunkEvent? loadingProgress) { 778 + loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
783 if (loadingProgress == null) { 779 if (loadingProgress == null) {
784 return child; 780 return child;
785 } 781 }
786 return CustomImageLoading( 782 return CustomImageLoading(
787 - progress: loadingProgress.expectedTotalBytes != null  
788 - ? loadingProgress.cumulativeBytesLoaded /  
789 - loadingProgress.expectedTotalBytes!  
790 - : 1, 783 + progress: loadingProgress.expectedTotalBytes != null ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! : 1,
791 ); 784 );
792 }, 785 },
793 fit: BoxFit.fill, 786 fit: BoxFit.fill,
@@ -811,15 +804,12 @@ class TableMd extends BlockMd { @@ -811,15 +804,12 @@ class TableMd extends BlockMd {
811 void Function(String url, String title)? onLinkTab, 804 void Function(String url, String title)? onLinkTab,
812 final String Function(String tex)? latexWorkaround, 805 final String Function(String tex)? latexWorkaround,
813 final Widget Function(BuildContext context, String tex)? latexBuilder, 806 final Widget Function(BuildContext context, String tex)? latexBuilder,
  807 + final Widget Function(BuildContext context, String tex)? codeBuilder,
814 ) { 808 ) {
815 final List<Map<int, String>> value = text 809 final List<Map<int, String>> value = text
816 .split('\n') 810 .split('\n')
817 .map<Map<int, String>>( 811 .map<Map<int, String>>(
818 - (e) => e  
819 - .split('|')  
820 - .where((element) => element.isNotEmpty)  
821 - .toList()  
822 - .asMap(), 812 + (e) => e.split('|').where((element) => element.isNotEmpty).toList().asMap(),
823 ) 813 )
824 .toList(); 814 .toList();
825 bool heading = RegExp( 815 bool heading = RegExp(
@@ -850,9 +840,7 @@ class TableMd extends BlockMd { @@ -850,9 +840,7 @@ class TableMd extends BlockMd {
850 (entry) => TableRow( 840 (entry) => TableRow(
851 decoration: (heading) 841 decoration: (heading)
852 ? BoxDecoration( 842 ? BoxDecoration(
853 - color: (entry.key == 0)  
854 - ? Theme.of(context).colorScheme.surfaceVariant  
855 - : null, 843 + color: (entry.key == 0) ? Theme.of(context).colorScheme.surfaceVariant : null,
856 ) 844 )
857 : null, 845 : null,
858 children: List.generate( 846 children: List.generate(
@@ -860,15 +848,13 @@ class TableMd extends BlockMd { @@ -860,15 +848,13 @@ class TableMd extends BlockMd {
860 (index) { 848 (index) {
861 var e = entry.value; 849 var e = entry.value;
862 String data = e[index] ?? ""; 850 String data = e[index] ?? "";
863 - if (RegExp(r"^--+$").hasMatch(data.trim()) ||  
864 - data.trim().isEmpty) { 851 + if (RegExp(r"^--+$").hasMatch(data.trim()) || data.trim().isEmpty) {
865 return const SizedBox(); 852 return const SizedBox();
866 } 853 }
867 854
868 return Center( 855 return Center(
869 child: Padding( 856 child: Padding(
870 - padding: const EdgeInsets.symmetric(  
871 - horizontal: 8, vertical: 4), 857 + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
872 child: MdWidget( 858 child: MdWidget(
873 (e[index] ?? "").trim(), 859 (e[index] ?? "").trim(),
874 textDirection: textDirection, 860 textDirection: textDirection,
@@ -909,13 +895,14 @@ class CodeBlockMd extends BlockMd { @@ -909,13 +895,14 @@ class CodeBlockMd extends BlockMd {
909 final void Function(String url, String title)? onLinkTab, 895 final void Function(String url, String title)? onLinkTab,
910 final String Function(String tex)? latexWorkaround, 896 final String Function(String tex)? latexWorkaround,
911 final Widget Function(BuildContext context, String tex)? latexBuilder, 897 final Widget Function(BuildContext context, String tex)? latexBuilder,
  898 + final Widget Function(BuildContext context, String tex)? codeBuilder,
912 ) { 899 ) {
913 String codes = exp.firstMatch(text)?[2] ?? ""; 900 String codes = exp.firstMatch(text)?[2] ?? "";
914 String name = exp.firstMatch(text)?[1] ?? ""; 901 String name = exp.firstMatch(text)?[1] ?? "";
915 codes = codes.replaceAll(r"```", "").trim(); 902 codes = codes.replaceAll(r"```", "").trim();
916 return Padding( 903 return Padding(
917 padding: const EdgeInsets.all(16.0), 904 padding: const EdgeInsets.all(16.0),
918 - child: CodeField(name: name, codes: codes), 905 + child: codeBuilder != null ? codeBuilder(context, codes) : CodeField(name: name, codes: codes),
919 ); 906 );
920 } 907 }
921 } 908 }
@@ -944,8 +931,7 @@ class _CodeFieldState extends State<CodeField> { @@ -944,8 +931,7 @@ class _CodeFieldState extends State<CodeField> {
944 Row( 931 Row(
945 children: [ 932 children: [
946 Padding( 933 Padding(
947 - padding:  
948 - const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8), 934 + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8),
949 child: Text(widget.name), 935 child: Text(widget.name),
950 ), 936 ),
951 const Spacer(), 937 const Spacer(),
@@ -957,8 +943,7 @@ class _CodeFieldState extends State<CodeField> { @@ -957,8 +943,7 @@ class _CodeFieldState extends State<CodeField> {
957 ), 943 ),
958 ), 944 ),
959 onPressed: () async { 945 onPressed: () async {
960 - await Clipboard.setData(ClipboardData(text: widget.codes))  
961 - .then((value) { 946 + await Clipboard.setData(ClipboardData(text: widget.codes)).then((value) {
962 setState(() { 947 setState(() {
963 _copied = true; 948 _copied = true;
964 }); 949 });
@@ -5,16 +5,19 @@ import 'package:gpt_markdown/markdown_component.dart'; @@ -5,16 +5,19 @@ import 'package:gpt_markdown/markdown_component.dart';
5 5
6 /// It creates a markdown widget closed to each other. 6 /// It creates a markdown widget closed to each other.
7 class MdWidget extends StatelessWidget { 7 class MdWidget extends StatelessWidget {
8 - const MdWidget(this.exp,  
9 - {super.key,  
10 - this.style,  
11 - this.textDirection = TextDirection.ltr,  
12 - this.onLinkTab,  
13 - this.textAlign,  
14 - this.textScaleFactor,  
15 - this.latexWorkaround,  
16 - this.latexBuilder,  
17 - this.followLinkColor = false}); 8 + const MdWidget(
  9 + this.exp, {
  10 + super.key,
  11 + this.style,
  12 + this.textDirection = TextDirection.ltr,
  13 + this.onLinkTab,
  14 + this.textAlign,
  15 + this.textScaleFactor,
  16 + this.latexWorkaround,
  17 + this.latexBuilder,
  18 + this.followLinkColor = false,
  19 + this.codeBuilder,
  20 + });
18 final String exp; 21 final String exp;
19 final TextDirection textDirection; 22 final TextDirection textDirection;
20 final TextStyle? style; 23 final TextStyle? style;
@@ -24,6 +27,7 @@ class MdWidget extends StatelessWidget { @@ -24,6 +27,7 @@ class MdWidget extends StatelessWidget {
24 final String Function(String tex)? latexWorkaround; 27 final String Function(String tex)? latexWorkaround;
25 final Widget Function(BuildContext context, String tex)? latexBuilder; 28 final Widget Function(BuildContext context, String tex)? latexBuilder;
26 final bool followLinkColor; 29 final bool followLinkColor;
  30 + final Widget Function(BuildContext context, String tex)? codeBuilder;
27 31
28 @override 32 @override
29 Widget build(BuildContext context) { 33 Widget build(BuildContext context) {
@@ -46,6 +50,7 @@ class MdWidget extends StatelessWidget { @@ -46,6 +50,7 @@ class MdWidget extends StatelessWidget {
46 onLinkTab, 50 onLinkTab,
47 latexWorkaround, 51 latexWorkaround,
48 latexBuilder, 52 latexBuilder,
  53 + codeBuilder,
49 ), 54 ),
50 ); 55 );
51 return Text.rich( 56 return Text.rich(