Showing
1 changed file
with
16 additions
and
5 deletions
@@ -61,19 +61,29 @@ class GptMarkdown extends StatelessWidget { | @@ -61,19 +61,29 @@ 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(); |
68 | - if (!tex.contains(r"\(")) { | ||
69 | - tex = tex | ||
70 | - .replaceAllMapped( | 79 | + tex = tex.replaceAllMapped( |
71 | RegExp( | 80 | RegExp( |
72 | r"(?<!\\)\$\$(.*?)(?<!\\)\$\$", | 81 | r"(?<!\\)\$\$(.*?)(?<!\\)\$\$", |
73 | dotAll: true, | 82 | dotAll: true, |
74 | ), | 83 | ), |
75 | - (match) => "\\[${match[1] ?? ""}\\]") | ||
76 | - .replaceAllMapped( | 84 | + (match) => "\\[${match[1] ?? ""}\\]"); |
85 | + if (!tex.contains(r"\(")) { | ||
86 | + tex = tex.replaceAllMapped( | ||
77 | RegExp( | 87 | RegExp( |
78 | r"(?<!\\)\$(.*?)(?<!\\)\$", | 88 | r"(?<!\\)\$(.*?)(?<!\\)\$", |
79 | ), | 89 | ), |
@@ -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, |
-
Please register or login to post a comment