SUY

add codeBuilder

@@ -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 });