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
David NAISSE
2025-01-09 17:44:44 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ba0b14626e77172dfae5386b91da496125efe2e8
ba0b1462
1 parent
ca32d50e
added linkBuilder
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
lib/custom_widgets/markdow_config.dart
lib/gpt_markdown.dart
lib/markdown_component.dart
lib/custom_widgets/markdow_config.dart
View file @
ba0b146
...
...
@@ -13,6 +13,7 @@ class GptMarkdownConfig {
this
.
codeBuilder
,
this
.
sourceTagBuilder
,
this
.
highlightBuilder
,
this
.
linkBuilder
,
this
.
maxLines
,
this
.
overflow
,
});
...
...
@@ -34,6 +35,7 @@ class GptMarkdownConfig {
final
int
?
maxLines
;
final
TextOverflow
?
overflow
;
final
Widget
Function
(
BuildContext
context
,
String
text
,
TextStyle
style
)?
highlightBuilder
;
final
Widget
Function
(
BuildContext
context
,
String
text
,
String
url
,
TextStyle
style
)?
linkBuilder
;
GptMarkdownConfig
copyWith
({
TextStyle
?
style
,
...
...
@@ -54,6 +56,7 @@ class GptMarkdownConfig {
final
int
?
maxLines
,
final
TextOverflow
?
overflow
,
final
Widget
Function
(
BuildContext
context
,
String
text
,
TextStyle
style
)?
highlightBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
text
,
String
url
,
TextStyle
style
)?
linkBuilder
,
})
{
return
GptMarkdownConfig
(
style:
style
??
this
.
style
,
...
...
@@ -69,6 +72,7 @@ class GptMarkdownConfig {
maxLines:
maxLines
??
this
.
maxLines
,
overflow:
overflow
??
this
.
overflow
,
highlightBuilder:
highlightBuilder
??
this
.
highlightBuilder
,
linkBuilder:
linkBuilder
??
this
.
linkBuilder
,
);
}
...
...
lib/gpt_markdown.dart
View file @
ba0b146
...
...
@@ -35,6 +35,7 @@ class GptMarkdown extends StatelessWidget {
this
.
codeBuilder
,
this
.
sourceTagBuilder
,
this
.
highlightBuilder
,
this
.
linkBuilder
,
this
.
maxLines
,
this
.
overflow
,
});
...
...
@@ -55,6 +56,7 @@ class GptMarkdown extends StatelessWidget {
codeBuilder
;
final
Widget
Function
(
BuildContext
,
String
,
TextStyle
)?
sourceTagBuilder
;
final
Widget
Function
(
BuildContext
context
,
String
text
,
TextStyle
style
)?
highlightBuilder
;
final
Widget
Function
(
BuildContext
context
,
String
text
,
String
url
,
TextStyle
style
)?
linkBuilder
;
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -96,6 +98,7 @@ class GptMarkdown extends StatelessWidget {
overflow:
overflow
,
sourceTagBuilder:
sourceTagBuilder
,
highlightBuilder:
highlightBuilder
,
linkBuilder:
linkBuilder
,
),
));
}
...
...
lib/markdown_component.dart
View file @
ba0b146
...
...
@@ -733,15 +733,35 @@ class ATagMd extends InlineMd {
if
(
match
?[
1
]
==
null
&&
match
?[
2
]
==
null
)
{
return
const
TextSpan
();
}
final
linkText
=
match
?[
1
]
??
""
;
final
url
=
match
?[
2
]
??
""
;
// Use custom builder if provided
if
(
config
.
linkBuilder
!=
null
)
{
return
WidgetSpan
(
child:
GestureDetector
(
onTap:
()
=>
config
.
onLinkTab
?.
call
(
url
,
linkText
),
child:
config
.
linkBuilder
!(
context
,
linkText
,
url
,
config
.
style
??
const
TextStyle
(),
),
),
);
}
// Default rendering
var
theme
=
GptMarkdownTheme
.
of
(
context
);
return
WidgetSpan
(
child:
LinkButton
(
hoverColor:
theme
.
linkHoverColor
,
color:
theme
.
linkColor
,
onPressed:
()
{
config
.
onLinkTab
?.
call
(
"
${match?[2]}
"
,
"
${match?[1]}
"
);
config
.
onLinkTab
?.
call
(
url
,
linkText
);
},
text:
match
?[
1
]
??
""
,
text:
linkText
,
config:
config
,
),
);
...
...
Please
register
or
login
to post a comment