saminsohag

source config added

  1 +## 0.1.9
  2 +
  3 +* source config added.
  4 +
1 ## 0.1.8 5 ## 0.1.8
2 6
3 * unordered list bullet color fixed. 7 * unordered list bullet color fixed.
@@ -326,6 +326,24 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -326,6 +326,24 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
326 ); 326 );
327 return child; 327 return child;
328 }, 328 },
  329 + sourceTagBuilder:
  330 + (buildContext, string, textStyle) {
  331 + var value = int.tryParse(string);
  332 + value ??= -1;
  333 + value += 1;
  334 + return SizedBox(
  335 + height: 20,
  336 + width: 20,
  337 + child: Container(
  338 + decoration: BoxDecoration(
  339 + color: Colors.red,
  340 + borderRadius:
  341 + BorderRadius.circular(10),
  342 + ),
  343 + child: Center(child: Text("$value")),
  344 + ),
  345 + );
  346 + },
329 ), 347 ),
330 ), 348 ),
331 // child: const Text("Hello"), 349 // child: const Text("Hello"),
@@ -190,7 +190,7 @@ packages: @@ -190,7 +190,7 @@ packages:
190 path: ".." 190 path: ".."
191 relative: true 191 relative: true
192 source: path 192 source: path
193 - version: "0.1.8" 193 + version: "0.1.9"
194 http: 194 http:
195 dependency: transitive 195 dependency: transitive
196 description: 196 description:
@@ -11,6 +11,7 @@ class GptMarkdownConfig { @@ -11,6 +11,7 @@ class GptMarkdownConfig {
11 this.latexBuilder, 11 this.latexBuilder,
12 this.followLinkColor = false, 12 this.followLinkColor = false,
13 this.codeBuilder, 13 this.codeBuilder,
  14 + this.sourceTagBuilder,
14 this.maxLines, 15 this.maxLines,
15 this.overflow, 16 this.overflow,
16 }); 17 });
@@ -23,11 +24,15 @@ class GptMarkdownConfig { @@ -23,11 +24,15 @@ class GptMarkdownConfig {
23 final Widget Function( 24 final Widget Function(
24 BuildContext context, String tex, TextStyle textStyle, bool inline)? 25 BuildContext context, String tex, TextStyle textStyle, bool inline)?
25 latexBuilder; 26 latexBuilder;
  27 + final Widget Function(
  28 + BuildContext context, String content, TextStyle textStyle)?
  29 + sourceTagBuilder;
26 final bool followLinkColor; 30 final bool followLinkColor;
27 final Widget Function(BuildContext context, String name, String code)? 31 final Widget Function(BuildContext context, String name, String code)?
28 codeBuilder; 32 codeBuilder;
29 final int? maxLines; 33 final int? maxLines;
30 final TextOverflow? overflow; 34 final TextOverflow? overflow;
  35 +
31 GptMarkdownConfig copyWith({ 36 GptMarkdownConfig copyWith({
32 TextStyle? style, 37 TextStyle? style,
33 TextDirection? textDirection, 38 TextDirection? textDirection,
@@ -38,6 +43,9 @@ class GptMarkdownConfig { @@ -38,6 +43,9 @@ class GptMarkdownConfig {
38 final Widget Function( 43 final Widget Function(
39 BuildContext context, String tex, TextStyle textStyle, bool inline)? 44 BuildContext context, String tex, TextStyle textStyle, bool inline)?
40 latexBuilder, 45 latexBuilder,
  46 + final Widget Function(
  47 + BuildContext context, String content, TextStyle textStyle)?
  48 + sourceTagBuilder,
41 bool? followLinkColor, 49 bool? followLinkColor,
42 final Widget Function(BuildContext context, String name, String code)? 50 final Widget Function(BuildContext context, String name, String code)?
43 codeBuilder, 51 codeBuilder,
@@ -54,6 +62,7 @@ class GptMarkdownConfig { @@ -54,6 +62,7 @@ class GptMarkdownConfig {
54 latexBuilder: latexBuilder ?? this.latexBuilder, 62 latexBuilder: latexBuilder ?? this.latexBuilder,
55 followLinkColor: followLinkColor ?? this.followLinkColor, 63 followLinkColor: followLinkColor ?? this.followLinkColor,
56 codeBuilder: codeBuilder ?? this.codeBuilder, 64 codeBuilder: codeBuilder ?? this.codeBuilder,
  65 + sourceTagBuilder: sourceTagBuilder ?? this.sourceTagBuilder,
57 maxLines: maxLines ?? this.maxLines, 66 maxLines: maxLines ?? this.maxLines,
58 overflow: overflow ?? this.overflow, 67 overflow: overflow ?? this.overflow,
59 ); 68 );
@@ -19,6 +19,7 @@ class TexMarkdown extends StatelessWidget { @@ -19,6 +19,7 @@ class TexMarkdown extends StatelessWidget {
19 this.onLinkTab, 19 this.onLinkTab,
20 this.latexBuilder, 20 this.latexBuilder,
21 this.codeBuilder, 21 this.codeBuilder,
  22 + this.sourceTagBuilder,
22 this.maxLines, 23 this.maxLines,
23 this.overflow, 24 this.overflow,
24 }); 25 });
@@ -37,6 +38,7 @@ class TexMarkdown extends StatelessWidget { @@ -37,6 +38,7 @@ class TexMarkdown extends StatelessWidget {
37 final bool followLinkColor; 38 final bool followLinkColor;
38 final Widget Function(BuildContext context, String name, String code)? 39 final Widget Function(BuildContext context, String name, String code)?
39 codeBuilder; 40 codeBuilder;
  41 + final Widget Function(BuildContext, String, TextStyle)? sourceTagBuilder;
40 42
41 @override 43 @override
42 Widget build(BuildContext context) { 44 Widget build(BuildContext context) {
@@ -76,6 +78,7 @@ class TexMarkdown extends StatelessWidget { @@ -76,6 +78,7 @@ class TexMarkdown extends StatelessWidget {
76 codeBuilder: codeBuilder, 78 codeBuilder: codeBuilder,
77 maxLines: maxLines, 79 maxLines: maxLines,
78 overflow: overflow, 80 overflow: overflow,
  81 + sourceTagBuilder: sourceTagBuilder,
79 ), 82 ),
80 )); 83 ));
81 } 84 }
@@ -618,7 +618,7 @@ class ItalicMd extends InlineMd { @@ -618,7 +618,7 @@ class ItalicMd extends InlineMd {
618 /// source text component 618 /// source text component
619 class SourceTag extends InlineMd { 619 class SourceTag extends InlineMd {
620 @override 620 @override
621 - RegExp get exp => RegExp(r"\[(\d+?)\]"); 621 + RegExp get exp => RegExp(r"(?:【.*?)?\[(\d+?)\]");
622 622
623 @override 623 @override
624 InlineSpan span( 624 InlineSpan span(
@@ -627,7 +627,8 @@ class SourceTag extends InlineMd { @@ -627,7 +627,8 @@ class SourceTag extends InlineMd {
627 final GptMarkdownConfig config, 627 final GptMarkdownConfig config,
628 ) { 628 ) {
629 var match = exp.firstMatch(text.trim()); 629 var match = exp.firstMatch(text.trim());
630 - if (match?[1] == null) { 630 + var content = match?[1];
  631 + if (content == null) {
631 return const TextSpan(); 632 return const TextSpan();
632 } 633 }
633 return WidgetSpan( 634 return WidgetSpan(
@@ -635,22 +636,24 @@ class SourceTag extends InlineMd { @@ -635,22 +636,24 @@ class SourceTag extends InlineMd {
635 // baseline: TextBaseline.alphabetic, 636 // baseline: TextBaseline.alphabetic,
636 child: Padding( 637 child: Padding(
637 padding: const EdgeInsets.all(2), 638 padding: const EdgeInsets.all(2),
638 - child: SizedBox(  
639 - width: 20,  
640 - height: 20,  
641 - child: Material(  
642 - color: Theme.of(context).colorScheme.onInverseSurface,  
643 - shape: const OvalBorder(),  
644 - child: FittedBox(  
645 - fit: BoxFit.scaleDown,  
646 - child: Text(  
647 - "${match?[1]}",  
648 - // style: (style ?? const TextStyle()).copyWith(),  
649 - textDirection: config.textDirection, 639 + child: config.sourceTagBuilder
  640 + ?.call(context, content, const TextStyle()) ??
  641 + SizedBox(
  642 + width: 20,
  643 + height: 20,
  644 + child: Material(
  645 + color: Theme.of(context).colorScheme.onInverseSurface,
  646 + shape: const OvalBorder(),
  647 + child: FittedBox(
  648 + fit: BoxFit.scaleDown,
  649 + child: Text(
  650 + content,
  651 + // style: (style ?? const TextStyle()).copyWith(),
  652 + textDirection: config.textDirection,
  653 + ),
  654 + ),
650 ), 655 ),
651 ), 656 ),
652 - ),  
653 - ),  
654 ), 657 ),
655 ); 658 );
656 } 659 }
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.8 3 +version: 0.1.9
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: