Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
gpt_markdown
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Mahmoud Abulmagd
2025-03-04 11:19:25 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
af38d62f148363bc2d57b1038bbef643e47c9ac1
af38d62f
1 parent
a05f9cc5
Add imageBuilder to config
Add imageBuilder to example Fix file name typo
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
11 deletions
example/lib/main.dart
lib/custom_widgets/link_button.dart
lib/custom_widgets/markdow_config.dart → lib/custom_widgets/markdown_config.dart
lib/gpt_markdown.dart
lib/markdown_component.dart
example/lib/main.dart
View file @
af38d62
...
...
@@ -328,8 +328,15 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
RegExp(r"align
\
*"),
(match) => "aligned");
},
imageBuilder: (context, url) {
return Image.network(
url,
width: 100,
height: 100,
);
},
latexBuilder:
(contex, tex, textStyle, inline) {
(contex
t
, tex, textStyle, inline) {
if (tex.contains(r"
\
begin{tabular}")) {
// return table.
String tableString = "|
${(RegExp(
...
...
lib/custom_widgets/link_button.dart
View file @
af38d62
import
'package:flutter/material.dart'
;
import
'markdow_config.dart'
;
import
'markdow
n
_config.dart'
;
class
LinkButton
extends
StatefulWidget
{
final
String
text
;
...
...
lib/custom_widgets/markdow_config.dart → lib/custom_widgets/markdow
n
_config.dart
View file @
af38d62
...
...
@@ -14,6 +14,7 @@ class GptMarkdownConfig {
this
.
sourceTagBuilder
,
this
.
highlightBuilder
,
this
.
linkBuilder
,
this
.
imageBuilder
,
this
.
maxLines
,
this
.
overflow
,
});
...
...
@@ -55,6 +56,7 @@ class GptMarkdownConfig {
TextStyle
style
,
)?
linkBuilder
;
final
Widget
Function
(
BuildContext
,
String
imageUrl
)?
imageBuilder
;
GptMarkdownConfig
copyWith
({
TextStyle
?
style
,
...
...
@@ -95,6 +97,7 @@ class GptMarkdownConfig {
TextStyle
style
,
)?
linkBuilder
,
final
Widget
Function
(
BuildContext
,
String
imageUrl
)?
imageBuilder
,
})
{
return
GptMarkdownConfig
(
style:
style
??
this
.
style
,
...
...
@@ -111,6 +114,7 @@ class GptMarkdownConfig {
overflow:
overflow
??
this
.
overflow
,
highlightBuilder:
highlightBuilder
??
this
.
highlightBuilder
,
linkBuilder:
linkBuilder
??
this
.
linkBuilder
,
imageBuilder:
imageBuilder
??
this
.
imageBuilder
,
);
}
...
...
lib/gpt_markdown.dart
View file @
af38d62
import
'package:flutter/material.dart'
;
import
'package:gpt_markdown/custom_widgets/markdow_config.dart'
;
import
'package:gpt_markdown/custom_widgets/markdow
n
_config.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter_math_fork/flutter_math.dart'
;
...
...
@@ -28,6 +28,7 @@ class GptMarkdown extends StatelessWidget {
this
.
textDirection
=
TextDirection
.
ltr
,
this
.
latexWorkaround
,
this
.
textAlign
,
this
.
imageBuilder
,
this
.
textScaler
,
this
.
onLinkTab
,
this
.
latexBuilder
,
...
...
@@ -72,6 +73,7 @@ class GptMarkdown extends StatelessWidget {
TextStyle
style
,
)?
linkBuilder
;
final
Widget
Function
(
BuildContext
,
String
imageUrl
)?
imageBuilder
;
String
_removeExtraLinesInsideBlockLatex
(
String
text
)
{
return
text
.
replaceAllMapped
(
RegExp
(
r"\\\[(.*?)\\\]"
,
multiLine:
true
,
dotAll:
true
),
...
...
@@ -120,6 +122,7 @@ class GptMarkdown extends StatelessWidget {
sourceTagBuilder:
sourceTagBuilder
,
highlightBuilder:
highlightBuilder
,
linkBuilder:
linkBuilder
,
imageBuilder:
imageBuilder
,
),
),
);
...
...
lib/markdown_component.dart
View file @
af38d62
...
...
@@ -755,12 +755,11 @@ class ImageMd extends InlineMd {
width
=
double
.
tryParse
(
size
?[
1
]?.
toString
().
trim
()
??
'a'
);
height
=
double
.
tryParse
(
size
?[
2
]?.
toString
().
trim
()
??
'a'
);
}
return
WidgetSpan
(
alignment:
PlaceholderAlignment
.
bottom
,
child:
SizedBox
(
width:
width
,
height:
height
,
child:
Image
(
late
final
Widget
image
;
if
(
config
.
imageBuilder
!=
null
)
{
image
=
config
.
imageBuilder
!(
context
,
'
${match?[2]}
'
);
}
else
{
image
=
Image
(
image:
NetworkImage
(
"
${match?[2]}
"
),
loadingBuilder:
(
BuildContext
context
,
...
...
@@ -782,8 +781,11 @@ class ImageMd extends InlineMd {
errorBuilder:
(
context
,
error
,
stackTrace
)
{
return
const
CustomImageError
();
},
),
),
);
}
return
WidgetSpan
(
alignment:
PlaceholderAlignment
.
bottom
,
child:
SizedBox
(
width:
width
,
height:
height
,
child:
image
),
);
}
}
...
...
Please
register
or
login
to post a comment