Showing
4 changed files
with
43 additions
and
14 deletions
| @@ -317,6 +317,7 @@ This document was created to test the robustness of Markdown parsers and to ensu | @@ -317,6 +317,7 @@ This document was created to test the robustness of Markdown parsers and to ensu | ||
| 317 | 317 | ||
| 318 | bool writingMod = true; | 318 | bool writingMod = true; |
| 319 | bool selectable = false; | 319 | bool selectable = false; |
| 320 | + bool useDollarSignsForLatex = false; | ||
| 320 | 321 | ||
| 321 | @override | 322 | @override |
| 322 | Widget build(BuildContext context) { | 323 | Widget build(BuildContext context) { |
| @@ -331,6 +332,22 @@ This document was created to test the robustness of Markdown parsers and to ensu | @@ -331,6 +332,22 @@ This document was created to test the robustness of Markdown parsers and to ensu | ||
| 331 | IconButton( | 332 | IconButton( |
| 332 | onPressed: () { | 333 | onPressed: () { |
| 333 | setState(() { | 334 | setState(() { |
| 335 | + useDollarSignsForLatex = !useDollarSignsForLatex; | ||
| 336 | + }); | ||
| 337 | + }, | ||
| 338 | + icon: Icon( | ||
| 339 | + Icons.monetization_on_outlined, | ||
| 340 | + color: useDollarSignsForLatex | ||
| 341 | + ? Theme.of(context).colorScheme.onSurfaceVariant | ||
| 342 | + : Theme.of(context) | ||
| 343 | + .colorScheme | ||
| 344 | + .onSurface | ||
| 345 | + .withValues(alpha: 0.38), | ||
| 346 | + ), | ||
| 347 | + ), | ||
| 348 | + IconButton( | ||
| 349 | + onPressed: () { | ||
| 350 | + setState(() { | ||
| 334 | selectable = !selectable; | 351 | selectable = !selectable; |
| 335 | }); | 352 | }); |
| 336 | }, | 353 | }, |
| @@ -421,6 +438,8 @@ This document was created to test the robustness of Markdown parsers and to ensu | @@ -421,6 +438,8 @@ This document was created to test the robustness of Markdown parsers and to ensu | ||
| 421 | debugPrint(url); | 438 | debugPrint(url); |
| 422 | debugPrint(title); | 439 | debugPrint(title); |
| 423 | }, | 440 | }, |
| 441 | + useDollarSignsForLatex: | ||
| 442 | + useDollarSignsForLatex, | ||
| 424 | textAlign: TextAlign.justify, | 443 | textAlign: TextAlign.justify, |
| 425 | textScaler: const TextScaler.linear(1), | 444 | textScaler: const TextScaler.linear(1), |
| 426 | style: const TextStyle( | 445 | style: const TextStyle( |
| @@ -42,6 +42,7 @@ class GptMarkdown extends StatelessWidget { | @@ -42,6 +42,7 @@ class GptMarkdown extends StatelessWidget { | ||
| 42 | this.unOrderedListBuilder, | 42 | this.unOrderedListBuilder, |
| 43 | this.components, | 43 | this.components, |
| 44 | this.inlineComponents, | 44 | this.inlineComponents, |
| 45 | + this.useDollarSignsForLatex = false, | ||
| 45 | }); | 46 | }); |
| 46 | 47 | ||
| 47 | /// The direction of the text. | 48 | /// The direction of the text. |
| @@ -96,6 +97,9 @@ class GptMarkdown extends StatelessWidget { | @@ -96,6 +97,9 @@ class GptMarkdown extends StatelessWidget { | ||
| 96 | /// The unordered list builder. | 97 | /// The unordered list builder. |
| 97 | final UnOrderedListBuilder? unOrderedListBuilder; | 98 | final UnOrderedListBuilder? unOrderedListBuilder; |
| 98 | 99 | ||
| 100 | + /// Whether to use dollar signs for LaTeX. | ||
| 101 | + final bool useDollarSignsForLatex; | ||
| 102 | + | ||
| 99 | /// The list of components. | 103 | /// The list of components. |
| 100 | /// ```dart | 104 | /// ```dart |
| 101 | /// List<MarkdownComponent> components = [ | 105 | /// List<MarkdownComponent> components = [ |
| @@ -154,21 +158,23 @@ class GptMarkdown extends StatelessWidget { | @@ -154,21 +158,23 @@ class GptMarkdown extends StatelessWidget { | ||
| 154 | @override | 158 | @override |
| 155 | Widget build(BuildContext context) { | 159 | Widget build(BuildContext context) { |
| 156 | String tex = data.trim(); | 160 | String tex = data.trim(); |
| 157 | - tex = tex.replaceAllMapped( | ||
| 158 | - RegExp(r"(?<!\\)\$\$(.*?)(?<!\\)\$\$", dotAll: true), | ||
| 159 | - (match) => "\\[${match[1] ?? ""}\\]", | ||
| 160 | - ); | ||
| 161 | - if (!tex.contains(r"\(")) { | 161 | + if (useDollarSignsForLatex) { |
| 162 | tex = tex.replaceAllMapped( | 162 | tex = tex.replaceAllMapped( |
| 163 | - RegExp(r"(?<!\\)\$(.*?)(?<!\\)\$"), | ||
| 164 | - (match) => "\\(${match[1] ?? ""}\\)", | ||
| 165 | - ); | ||
| 166 | - tex = tex.splitMapJoin( | ||
| 167 | - RegExp(r"\[.*?\]|\(.*?\)"), | ||
| 168 | - onNonMatch: (p0) { | ||
| 169 | - return p0.replaceAll("\\\$", "\$"); | ||
| 170 | - }, | 163 | + RegExp(r"(?<!\\)\$\$(.*?)(?<!\\)\$\$", dotAll: true), |
| 164 | + (match) => "\\[${match[1] ?? ""}\\]", | ||
| 171 | ); | 165 | ); |
| 166 | + if (!tex.contains(r"\(")) { | ||
| 167 | + tex = tex.replaceAllMapped( | ||
| 168 | + RegExp(r"(?<!\\)\$(.*?)(?<!\\)\$"), | ||
| 169 | + (match) => "\\(${match[1] ?? ""}\\)", | ||
| 170 | + ); | ||
| 171 | + tex = tex.splitMapJoin( | ||
| 172 | + RegExp(r"\[.*?\]|\(.*?\)"), | ||
| 173 | + onNonMatch: (p0) { | ||
| 174 | + return p0.replaceAll("\\\$", "\$"); | ||
| 175 | + }, | ||
| 176 | + ); | ||
| 177 | + } | ||
| 172 | } | 178 | } |
| 173 | // tex = _removeExtraLinesInsideBlockLatex(tex); | 179 | // tex = _removeExtraLinesInsideBlockLatex(tex); |
| 174 | return ClipRRect( | 180 | return ClipRRect( |
| 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.17 | 3 | +version: 1.0.18 |
| 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