saminsohag

fixed block syntax and 24064..24064 syntax works by default

@@ -61,23 +61,33 @@ class GptMarkdown extends StatelessWidget { @@ -61,23 +61,33 @@ class GptMarkdown extends StatelessWidget {
61 final Widget Function( 61 final Widget Function(
62 BuildContext context, String text, String url, TextStyle style)? 62 BuildContext context, String text, String url, TextStyle style)?
63 linkBuilder; 63 linkBuilder;
  64 + String _removeExtraLinesInsideBlockLatex(String text) {
  65 + return text.replaceAllMapped(
  66 + RegExp(
  67 + r"\\\[(.*?)\\\]",
  68 + multiLine: true,
  69 + dotAll: true,
  70 + ), (match) {
  71 + String content = match[0] ?? "";
  72 + return content.replaceAllMapped(RegExp(r"\n[\n\ ]+"), (match) => "\n");
  73 + });
  74 + }
64 75
65 @override 76 @override
66 Widget build(BuildContext context) { 77 Widget build(BuildContext context) {
67 String tex = data.trim(); 78 String tex = data.trim();
  79 + tex = tex.replaceAllMapped(
  80 + RegExp(
  81 + r"(?<!\\)\$\$(.*?)(?<!\\)\$\$",
  82 + dotAll: true,
  83 + ),
  84 + (match) => "\\[${match[1] ?? ""}\\]");
68 if (!tex.contains(r"\(")) { 85 if (!tex.contains(r"\(")) {
69 - tex = tex  
70 - .replaceAllMapped(  
71 - RegExp(  
72 - r"(?<!\\)\$\$(.*?)(?<!\\)\$\$",  
73 - dotAll: true,  
74 - ),  
75 - (match) => "\\[${match[1] ?? ""}\\]")  
76 - .replaceAllMapped(  
77 - RegExp(  
78 - r"(?<!\\)\$(.*?)(?<!\\)\$",  
79 - ),  
80 - (match) => "\\(${match[1] ?? ""}\\)"); 86 + tex = tex.replaceAllMapped(
  87 + RegExp(
  88 + r"(?<!\\)\$(.*?)(?<!\\)\$",
  89 + ),
  90 + (match) => "\\(${match[1] ?? ""}\\)");
81 tex = tex.splitMapJoin( 91 tex = tex.splitMapJoin(
82 RegExp(r"\[.*?\]|\(.*?\)"), 92 RegExp(r"\[.*?\]|\(.*?\)"),
83 onNonMatch: (p0) { 93 onNonMatch: (p0) {
@@ -85,6 +95,7 @@ class GptMarkdown extends StatelessWidget { @@ -85,6 +95,7 @@ class GptMarkdown extends StatelessWidget {
85 }, 95 },
86 ); 96 );
87 } 97 }
  98 + tex = _removeExtraLinesInsideBlockLatex(tex);
88 return ClipRRect( 99 return ClipRRect(
89 child: MdWidget( 100 child: MdWidget(
90 tex, 101 tex,