Showing
6 changed files
with
66 additions
and
58 deletions
| 1 | +## 1.1.0 | ||
| 2 | + | ||
| 3 | +* Changed `onLinkTab` to `onLinkTap` fixed issues of newLine issues. | ||
| 4 | + | ||
| 1 | ## 1.0.20 | 5 | ## 1.0.20 |
| 2 | 6 | ||
| 3 | * Fix: support balanced parentheses in image and link URLs. [#68](https://github.com/Infinitix-LLC/gpt_markdown/pull/68) | 7 | * Fix: support balanced parentheses in image and link URLs. [#68](https://github.com/Infinitix-LLC/gpt_markdown/pull/68) |
| @@ -76,6 +76,10 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -76,6 +76,10 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 76 | TextDirection _direction = TextDirection.ltr; | 76 | TextDirection _direction = TextDirection.ltr; |
| 77 | final TextEditingController _controller = TextEditingController( | 77 | final TextEditingController _controller = TextEditingController( |
| 78 | text: r''' | 78 | text: r''' |
| 79 | +decsiob (*) is on the set PQ = {91, 905} jjjzjsx * jjdbhsjsjmamajmsghdhhi msnnsjnskaksjjshahsh | ||
| 80 | + | ||
| 81 | +(*) | ||
| 82 | + | ||
| 79 | This is a sample markdown document. | 83 | This is a sample markdown document. |
| 80 | 84 | ||
| 81 | * **bold** | 85 | * **bold** |
| @@ -444,7 +448,7 @@ This document was created to test the robustness of Markdown parsers and to ensu | @@ -444,7 +448,7 @@ This document was created to test the robustness of Markdown parsers and to ensu | ||
| 444 | Widget child = GptMarkdown( | 448 | Widget child = GptMarkdown( |
| 445 | _controller.text, | 449 | _controller.text, |
| 446 | textDirection: _direction, | 450 | textDirection: _direction, |
| 447 | - onLinkTab: (url, title) { | 451 | + onLinkTap: (url, title) { |
| 448 | debugPrint(url); | 452 | debugPrint(url); |
| 449 | debugPrint(title); | 453 | debugPrint(title); |
| 450 | }, | 454 | }, |
| @@ -615,40 +619,40 @@ This document was created to test the robustness of Markdown parsers and to ensu | @@ -615,40 +619,40 @@ This document was created to test the robustness of Markdown parsers and to ensu | ||
| 615 | ), | 619 | ), |
| 616 | ); | 620 | ); |
| 617 | }, | 621 | }, |
| 618 | - components: [ | ||
| 619 | - CodeBlockMd(), | ||
| 620 | - NewLines(), | ||
| 621 | - BlockQuote(), | ||
| 622 | - ImageMd(), | ||
| 623 | - ATagMd(), | ||
| 624 | - TableMd(), | ||
| 625 | - HTag(), | ||
| 626 | - UnOrderedList(), | ||
| 627 | - OrderedList(), | ||
| 628 | - RadioButtonMd(), | ||
| 629 | - CheckBoxMd(), | ||
| 630 | - HrLine(), | ||
| 631 | - StrikeMd(), | ||
| 632 | - BoldMd(), | ||
| 633 | - ItalicMd(), | ||
| 634 | - LatexMath(), | ||
| 635 | - LatexMathMultiLine(), | ||
| 636 | - HighlightedText(), | ||
| 637 | - SourceTag(), | ||
| 638 | - IndentMd(), | ||
| 639 | - ], | ||
| 640 | - inlineComponents: [ | ||
| 641 | - ImageMd(), | ||
| 642 | - ATagMd(), | ||
| 643 | - TableMd(), | ||
| 644 | - StrikeMd(), | ||
| 645 | - BoldMd(), | ||
| 646 | - ItalicMd(), | ||
| 647 | - LatexMath(), | ||
| 648 | - LatexMathMultiLine(), | ||
| 649 | - HighlightedText(), | ||
| 650 | - SourceTag(), | ||
| 651 | - ], | 622 | + // components: [ |
| 623 | + // CodeBlockMd(), | ||
| 624 | + // NewLines(), | ||
| 625 | + // BlockQuote(), | ||
| 626 | + // ImageMd(), | ||
| 627 | + // ATagMd(), | ||
| 628 | + // TableMd(), | ||
| 629 | + // HTag(), | ||
| 630 | + // UnOrderedList(), | ||
| 631 | + // OrderedList(), | ||
| 632 | + // RadioButtonMd(), | ||
| 633 | + // CheckBoxMd(), | ||
| 634 | + // HrLine(), | ||
| 635 | + // StrikeMd(), | ||
| 636 | + // BoldMd(), | ||
| 637 | + // ItalicMd(), | ||
| 638 | + // LatexMath(), | ||
| 639 | + // LatexMathMultiLine(), | ||
| 640 | + // HighlightedText(), | ||
| 641 | + // SourceTag(), | ||
| 642 | + // IndentMd(), | ||
| 643 | + // ], | ||
| 644 | + // inlineComponents: [ | ||
| 645 | + // ImageMd(), | ||
| 646 | + // ATagMd(), | ||
| 647 | + // TableMd(), | ||
| 648 | + // StrikeMd(), | ||
| 649 | + // BoldMd(), | ||
| 650 | + // ItalicMd(), | ||
| 651 | + // LatexMath(), | ||
| 652 | + // LatexMathMultiLine(), | ||
| 653 | + // HighlightedText(), | ||
| 654 | + // SourceTag(), | ||
| 655 | + // ], | ||
| 652 | // codeBuilder: (context, name, code, closed) { | 656 | // codeBuilder: (context, name, code, closed) { |
| 653 | // return Padding( | 657 | // return Padding( |
| 654 | // padding: const EdgeInsets.symmetric( | 658 | // padding: const EdgeInsets.symmetric( |
| @@ -61,12 +61,12 @@ typedef ImageBuilder = Widget Function(BuildContext context, String imageUrl); | @@ -61,12 +61,12 @@ typedef ImageBuilder = Widget Function(BuildContext context, String imageUrl); | ||
| 61 | /// The [GptMarkdownConfig] class is used to configure the GPT Markdown component. | 61 | /// The [GptMarkdownConfig] class is used to configure the GPT Markdown component. |
| 62 | /// It takes a [style] parameter to set the style of the text, | 62 | /// It takes a [style] parameter to set the style of the text, |
| 63 | /// a [textDirection] parameter to set the direction of the text, | 63 | /// a [textDirection] parameter to set the direction of the text, |
| 64 | -/// and an optional [onLinkTab] parameter to handle link clicks. | 64 | +/// and an optional [onLinkTap] parameter to handle link clicks. |
| 65 | class GptMarkdownConfig { | 65 | class GptMarkdownConfig { |
| 66 | const GptMarkdownConfig({ | 66 | const GptMarkdownConfig({ |
| 67 | this.style, | 67 | this.style, |
| 68 | this.textDirection = TextDirection.ltr, | 68 | this.textDirection = TextDirection.ltr, |
| 69 | - this.onLinkTab, | 69 | + this.onLinkTap, |
| 70 | this.textAlign, | 70 | this.textAlign, |
| 71 | this.textScaler, | 71 | this.textScaler, |
| 72 | this.latexWorkaround, | 72 | this.latexWorkaround, |
| @@ -98,7 +98,7 @@ class GptMarkdownConfig { | @@ -98,7 +98,7 @@ class GptMarkdownConfig { | ||
| 98 | final TextScaler? textScaler; | 98 | final TextScaler? textScaler; |
| 99 | 99 | ||
| 100 | /// The callback function to handle link clicks. | 100 | /// The callback function to handle link clicks. |
| 101 | - final void Function(String url, String title)? onLinkTab; | 101 | + final void Function(String url, String title)? onLinkTap; |
| 102 | 102 | ||
| 103 | /// The LaTeX workaround. | 103 | /// The LaTeX workaround. |
| 104 | final String Function(String tex)? latexWorkaround; | 104 | final String Function(String tex)? latexWorkaround; |
| @@ -146,7 +146,7 @@ class GptMarkdownConfig { | @@ -146,7 +146,7 @@ class GptMarkdownConfig { | ||
| 146 | GptMarkdownConfig copyWith({ | 146 | GptMarkdownConfig copyWith({ |
| 147 | TextStyle? style, | 147 | TextStyle? style, |
| 148 | TextDirection? textDirection, | 148 | TextDirection? textDirection, |
| 149 | - final void Function(String url, String title)? onLinkTab, | 149 | + final void Function(String url, String title)? onLinkTap, |
| 150 | final TextAlign? textAlign, | 150 | final TextAlign? textAlign, |
| 151 | final TextScaler? textScaler, | 151 | final TextScaler? textScaler, |
| 152 | final String Function(String tex)? latexWorkaround, | 152 | final String Function(String tex)? latexWorkaround, |
| @@ -167,7 +167,7 @@ class GptMarkdownConfig { | @@ -167,7 +167,7 @@ class GptMarkdownConfig { | ||
| 167 | return GptMarkdownConfig( | 167 | return GptMarkdownConfig( |
| 168 | style: style ?? this.style, | 168 | style: style ?? this.style, |
| 169 | textDirection: textDirection ?? this.textDirection, | 169 | textDirection: textDirection ?? this.textDirection, |
| 170 | - onLinkTab: onLinkTab ?? this.onLinkTab, | 170 | + onLinkTap: onLinkTap ?? this.onLinkTap, |
| 171 | textAlign: textAlign ?? this.textAlign, | 171 | textAlign: textAlign ?? this.textAlign, |
| 172 | textScaler: textScaler ?? this.textScaler, | 172 | textScaler: textScaler ?? this.textScaler, |
| 173 | latexWorkaround: latexWorkaround ?? this.latexWorkaround, | 173 | latexWorkaround: latexWorkaround ?? this.latexWorkaround, |
| @@ -218,7 +218,7 @@ class GptMarkdownConfig { | @@ -218,7 +218,7 @@ class GptMarkdownConfig { | ||
| 218 | // linkBuilder == other.linkBuilder && | 218 | // linkBuilder == other.linkBuilder && |
| 219 | // imageBuilder == other.imageBuilder && | 219 | // imageBuilder == other.imageBuilder && |
| 220 | // highlightBuilder == other.highlightBuilder && | 220 | // highlightBuilder == other.highlightBuilder && |
| 221 | - // onLinkTab == other.onLinkTab && | 221 | + // onLinkTap == other.onLinkTap && |
| 222 | textDirection == other.textDirection; | 222 | textDirection == other.textDirection; |
| 223 | } | 223 | } |
| 224 | } | 224 | } |
| @@ -30,7 +30,7 @@ class GptMarkdown extends StatelessWidget { | @@ -30,7 +30,7 @@ class GptMarkdown extends StatelessWidget { | ||
| 30 | this.textAlign, | 30 | this.textAlign, |
| 31 | this.imageBuilder, | 31 | this.imageBuilder, |
| 32 | this.textScaler, | 32 | this.textScaler, |
| 33 | - this.onLinkTab, | 33 | + this.onLinkTap, |
| 34 | this.latexBuilder, | 34 | this.latexBuilder, |
| 35 | this.codeBuilder, | 35 | this.codeBuilder, |
| 36 | this.sourceTagBuilder, | 36 | this.sourceTagBuilder, |
| @@ -61,7 +61,7 @@ class GptMarkdown extends StatelessWidget { | @@ -61,7 +61,7 @@ class GptMarkdown extends StatelessWidget { | ||
| 61 | final TextScaler? textScaler; | 61 | final TextScaler? textScaler; |
| 62 | 62 | ||
| 63 | /// The callback function to handle link clicks. | 63 | /// The callback function to handle link clicks. |
| 64 | - final void Function(String url, String title)? onLinkTab; | 64 | + final void Function(String url, String title)? onLinkTap; |
| 65 | 65 | ||
| 66 | /// The LaTeX workaround. | 66 | /// The LaTeX workaround. |
| 67 | final String Function(String tex)? latexWorkaround; | 67 | final String Function(String tex)? latexWorkaround; |
| @@ -185,7 +185,7 @@ class GptMarkdown extends StatelessWidget { | @@ -185,7 +185,7 @@ class GptMarkdown extends StatelessWidget { | ||
| 185 | config: GptMarkdownConfig( | 185 | config: GptMarkdownConfig( |
| 186 | textDirection: textDirection, | 186 | textDirection: textDirection, |
| 187 | style: style, | 187 | style: style, |
| 188 | - onLinkTab: onLinkTab, | 188 | + onLinkTap: onLinkTap, |
| 189 | textAlign: textAlign, | 189 | textAlign: textAlign, |
| 190 | textScaler: textScaler, | 190 | textScaler: textScaler, |
| 191 | followLinkColor: followLinkColor, | 191 | followLinkColor: followLinkColor, |
| @@ -2,12 +2,11 @@ part of 'gpt_markdown.dart'; | @@ -2,12 +2,11 @@ part of 'gpt_markdown.dart'; | ||
| 2 | 2 | ||
| 3 | /// Markdown components | 3 | /// Markdown components |
| 4 | abstract class MarkdownComponent { | 4 | abstract class MarkdownComponent { |
| 5 | - static final List<MarkdownComponent> components = [ | 5 | + static List<MarkdownComponent> get globalComponents => [ |
| 6 | CodeBlockMd(), | 6 | CodeBlockMd(), |
| 7 | + LatexMathMultiLine(), | ||
| 7 | NewLines(), | 8 | NewLines(), |
| 8 | BlockQuote(), | 9 | BlockQuote(), |
| 9 | - ImageMd(), | ||
| 10 | - ATagMd(), | ||
| 11 | TableMd(), | 10 | TableMd(), |
| 12 | HTag(), | 11 | HTag(), |
| 13 | UnOrderedList(), | 12 | UnOrderedList(), |
| @@ -15,13 +14,6 @@ abstract class MarkdownComponent { | @@ -15,13 +14,6 @@ abstract class MarkdownComponent { | ||
| 15 | RadioButtonMd(), | 14 | RadioButtonMd(), |
| 16 | CheckBoxMd(), | 15 | CheckBoxMd(), |
| 17 | HrLine(), | 16 | HrLine(), |
| 18 | - StrikeMd(), | ||
| 19 | - BoldMd(), | ||
| 20 | - ItalicMd(), | ||
| 21 | - LatexMath(), | ||
| 22 | - LatexMathMultiLine(), | ||
| 23 | - HighlightedText(), | ||
| 24 | - SourceTag(), | ||
| 25 | IndentMd(), | 17 | IndentMd(), |
| 26 | ]; | 18 | ]; |
| 27 | 19 | ||
| @@ -47,7 +39,7 @@ abstract class MarkdownComponent { | @@ -47,7 +39,7 @@ abstract class MarkdownComponent { | ||
| 47 | ) { | 39 | ) { |
| 48 | var components = | 40 | var components = |
| 49 | includeGlobalComponents | 41 | includeGlobalComponents |
| 50 | - ? config.components ?? MarkdownComponent.components | 42 | + ? config.components ?? MarkdownComponent.globalComponents |
| 51 | : config.inlineComponents ?? MarkdownComponent.inlineComponents; | 43 | : config.inlineComponents ?? MarkdownComponent.inlineComponents; |
| 52 | List<InlineSpan> spans = []; | 44 | List<InlineSpan> spans = []; |
| 53 | Iterable<String> regexes = components.map<String>((e) => e.exp.pattern); | 45 | Iterable<String> regexes = components.map<String>((e) => e.exp.pattern); |
| @@ -75,6 +67,14 @@ abstract class MarkdownComponent { | @@ -75,6 +67,14 @@ abstract class MarkdownComponent { | ||
| 75 | return ""; | 67 | return ""; |
| 76 | }, | 68 | }, |
| 77 | onNonMatch: (p0) { | 69 | onNonMatch: (p0) { |
| 70 | + if (p0.isEmpty) { | ||
| 71 | + return ""; | ||
| 72 | + } | ||
| 73 | + if (includeGlobalComponents) { | ||
| 74 | + var newSpans = generate(context, p0, config.copyWith(), false); | ||
| 75 | + spans.addAll(newSpans); | ||
| 76 | + return ""; | ||
| 77 | + } | ||
| 78 | spans.add(TextSpan(text: p0, style: config.style)); | 78 | spans.add(TextSpan(text: p0, style: config.style)); |
| 79 | return ""; | 79 | return ""; |
| 80 | }, | 80 | }, |
| @@ -830,7 +830,7 @@ class ATagMd extends InlineMd { | @@ -830,7 +830,7 @@ class ATagMd extends InlineMd { | ||
| 830 | if (builder != null) { | 830 | if (builder != null) { |
| 831 | return WidgetSpan( | 831 | return WidgetSpan( |
| 832 | child: GestureDetector( | 832 | child: GestureDetector( |
| 833 | - onTap: () => config.onLinkTab?.call(url, linkText), | 833 | + onTap: () => config.onLinkTap?.call(url, linkText), |
| 834 | child: builder( | 834 | child: builder( |
| 835 | context, | 835 | context, |
| 836 | linkText, | 836 | linkText, |
| @@ -848,7 +848,7 @@ class ATagMd extends InlineMd { | @@ -848,7 +848,7 @@ class ATagMd extends InlineMd { | ||
| 848 | hoverColor: theme.linkHoverColor, | 848 | hoverColor: theme.linkHoverColor, |
| 849 | color: theme.linkColor, | 849 | color: theme.linkColor, |
| 850 | onPressed: () { | 850 | onPressed: () { |
| 851 | - config.onLinkTab?.call(url, linkText); | 851 | + config.onLinkTap?.call(url, linkText); |
| 852 | }, | 852 | }, |
| 853 | text: linkText, | 853 | text: linkText, |
| 854 | config: config, | 854 | config: config, |
| 1 | name: gpt_markdown | 1 | name: gpt_markdown |
| 2 | description: "Powerful Markdown & LaTeX Renderer for Flutter: Rich Text, Math, Tables, Links, and Text Selection. Ideal for ChatGPT, Gemini, and more." | 2 | description: "Powerful Markdown & LaTeX Renderer for Flutter: Rich Text, Math, Tables, Links, and Text Selection. Ideal for ChatGPT, Gemini, and more." |
| 3 | -version: 1.0.20 | 3 | +version: 1.1.0 |
| 4 | homepage: https://github.com/Infinitix-LLC/gpt_markdown | 4 | homepage: https://github.com/Infinitix-LLC/gpt_markdown |
| 5 | 5 | ||
| 6 | environment: | 6 | environment: |
-
Please register or login to post a comment