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
Samin yeasar Sohag
2024-02-22 07:55:46 +0600
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
GitHub
2024-02-22 07:55:46 +0600
Commit
f92a04d77c34f2520cfd7a6646ad6f236674b3c1
f92a04d7
2 parents
ff7dae8e
9e051064
Merge pull request #7 from suysoftware/main
add CodeBuilder feature
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
95 additions
and
119 deletions
gpt_markdown/example/lib/main.dart
gpt_markdown/example/macos/Runner.xcodeproj/project.pbxproj
gpt_markdown/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
gpt_markdown/example/pubspec.lock
gpt_markdown/lib/gpt_markdown.dart
gpt_markdown/lib/markdown_component.dart
gpt_markdown/lib/md_widget.dart
gpt_markdown/example/lib/main.dart
View file @
f92a04d
...
...
@@ -67,6 +67,21 @@ Welcome to ChatGPT! Below is an example of a response with Markdown and LaTeX co
### Markdown Example
```
class MarkdownHelper {
Map<String, Widget> getTitleWidget(m.Node node) => title.getTitleWidget(node);
Widget getPWidget(m.Element node) => p.getPWidget(node);
Widget getPreWidget(m.Node node) => pre.getPreWidget(node);
}
```
You can use Markdown to format text easily. Here are some examples:
- **Bold Text**: **This text is bold**
...
...
gpt_markdown/example/macos/Runner.xcodeproj/project.pbxproj
View file @
f92a04d
...
...
@@ -259,7 +259,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1
51
0;
LastUpgradeCheck = 1
43
0;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
...
...
gpt_markdown/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
View file @
f92a04d
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion =
"1
51
0"
LastUpgradeVersion =
"1
43
0"
version =
"1.3"
>
<BuildAction
parallelizeBuildables =
"YES"
...
...
gpt_markdown/example/pubspec.lock
View file @
f92a04d
...
...
@@ -215,30 +215,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
...
...
@@ -251,26 +227,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256:
d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
sha256:
"1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.16
+1
"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "
0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a
"
sha256: "
9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41
"
url: "https://pub.dev"
source: hosted
version: "0.
8
.0"
version: "0.
5
.0"
meta:
dependency: transitive
description:
name: meta
sha256:
d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
sha256:
a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.1
1
.0"
version: "1.1
0
.0"
nested:
dependency: transitive
description:
...
...
@@ -283,10 +259,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "
087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af
"
sha256: "
8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917
"
url: "https://pub.dev"
source: hosted
version: "1.
9.0
"
version: "1.
8.3
"
path_parsing:
dependency: transitive
description:
...
...
@@ -612,14 +588,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
...
...
gpt_markdown/lib/gpt_markdown.dart
View file @
f92a04d
...
...
@@ -17,6 +17,7 @@ class TexMarkdown extends StatelessWidget {
this
.
textScaleFactor
,
this
.
onLinkTab
,
this
.
latexBuilder
,
this
.
codeBuilder
,
});
final
TextDirection
textDirection
;
final
String
data
;
...
...
@@ -27,6 +28,7 @@ class TexMarkdown extends StatelessWidget {
final
String
Function
(
String
tex
)?
latexWorkaround
;
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
;
final
bool
followLinkColor
;
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
;
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -62,6 +64,7 @@ class TexMarkdown extends StatelessWidget {
followLinkColor:
followLinkColor
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
codeBuilder:
codeBuilder
,
));
}
}
...
...
gpt_markdown/lib/markdown_component.dart
View file @
f92a04d
...
...
@@ -38,10 +38,10 @@ abstract class MarkdownComponent {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
List
<
InlineSpan
>
spans
=
[];
List
<
String
>
regexes
=
components
.
map
<
String
>((
e
)
=>
e
.
exp
.
pattern
).
toList
();
List
<
String
>
regexes
=
components
.
map
<
String
>((
e
)
=>
e
.
exp
.
pattern
).
toList
();
final
combinedRegex
=
RegExp
(
regexes
.
join
(
"|"
),
multiLine:
true
,
...
...
@@ -64,6 +64,7 @@ abstract class MarkdownComponent {
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
,
));
}
else
{
if
(
each
is
BlockMd
)
{
...
...
@@ -84,6 +85,7 @@ abstract class MarkdownComponent {
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
,
),
TextSpan
(
text:
"
\n
"
,
...
...
@@ -123,6 +125,7 @@ abstract class MarkdownComponent {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
);
RegExp
get
exp
;
...
...
@@ -143,6 +146,7 @@ abstract class InlineMd extends MarkdownComponent {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
);
}
...
...
@@ -159,6 +163,7 @@ abstract class BlockMd extends MarkdownComponent {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
return
WidgetSpan
(
child:
build
(
...
...
@@ -169,6 +174,7 @@ abstract class BlockMd extends MarkdownComponent {
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
,
),
alignment:
PlaceholderAlignment
.
middle
,
);
...
...
@@ -182,6 +188,7 @@ abstract class BlockMd extends MarkdownComponent {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
);
}
...
...
@@ -198,6 +205,7 @@ class HTag extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
Text
.
rich
(
...
...
@@ -207,35 +215,18 @@ class HTag extends BlockMd {
context
,
"
${match?[2]}
"
,
[
Theme
.
of
(
context
)
.
textTheme
.
headlineLarge
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
headlineSmall
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
titleLarge
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
titleMedium
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
titleSmall
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
headlineLarge
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
headlineMedium
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
headlineSmall
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
titleLarge
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
titleMedium
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
titleSmall
?.
copyWith
(
color:
style
?.
color
),
][
match
![
1
]!.
length
-
1
],
textDirection
,
(
url
,
title
)
{},
latexWorkaround
,
latexBuilder
,
codeBuilder
,
)),
if
(
match
[
1
]!.
length
==
1
)
...[
const
TextSpan
(
...
...
@@ -268,6 +259,7 @@ class NewLines extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
return
TextSpan
(
text:
"
\n\n\n\n
"
,
...
...
@@ -292,6 +284,7 @@ class HrLine extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
return
CustomDivider
(
height:
2
,
...
...
@@ -315,6 +308,7 @@ class CheckBoxMd extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
CustomCb
(
...
...
@@ -347,6 +341,7 @@ class RadioButtonMd extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
CustomRb
(
...
...
@@ -379,6 +374,7 @@ class IndentMd extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
[
r"\\\[(.*?)\\\]"
,
...
...
@@ -394,8 +390,7 @@ class IndentMd extends BlockMd {
textDirection:
textDirection
,
child:
RichText
(
text:
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[2]}
"
,
style
,
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
),
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[2]}
"
,
style
,
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
),
)),
);
}
...
...
@@ -416,6 +411,7 @@ class UnOrderedList extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
);
return
UnorderedListView
(
...
...
@@ -451,6 +447,7 @@ class OrderedList extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
OrderedListView
(
...
...
@@ -482,6 +479,7 @@ class HighlightedText extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
return
TextSpan
(
text:
text
,
...
...
@@ -517,21 +515,21 @@ class BoldMd extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[1]}
"
,
style
?.
copyWith
(
fontWeight:
FontWeight
.
bold
)
??
const
TextStyle
(
fontWeight:
FontWeight
.
w900
),
style
?.
copyWith
(
fontWeight:
FontWeight
.
bold
)
??
const
TextStyle
(
fontWeight:
FontWeight
.
w900
),
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
,
),
style:
style
?.
copyWith
(
fontWeight:
FontWeight
.
bold
)
??
const
TextStyle
(
fontWeight:
FontWeight
.
bold
),
style:
style
?.
copyWith
(
fontWeight:
FontWeight
.
bold
)
??
const
TextStyle
(
fontWeight:
FontWeight
.
bold
),
);
}
}
...
...
@@ -552,6 +550,7 @@ class LatexMathMultyLine extends BlockMd {
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
String
Function
(
String
tex
)?
latexWorkaround
,
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
p0
=
exp
.
firstMatch
(
text
.
trim
());
p0
?.
group
(
0
);
...
...
@@ -572,8 +571,7 @@ class LatexMathMultyLine extends BlockMd {
options:
MathOptions
(
sizeUnderTextStyle:
MathSize
.
large
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurface
,
fontSize:
style
?.
fontSize
??
Theme
.
of
(
context
).
textTheme
.
bodyMedium
?.
fontSize
,
fontSize:
style
?.
fontSize
??
Theme
.
of
(
context
).
textTheme
.
bodyMedium
?.
fontSize
,
mathFontOptions:
FontOptions
(
fontFamily:
"Main"
,
fontWeight:
style
?.
fontWeight
??
FontWeight
.
normal
,
...
...
@@ -590,9 +588,7 @@ class LatexMathMultyLine extends BlockMd {
return
Text
(
workaround
(
mathText
),
textDirection:
textDirection
,
style:
style
?.
copyWith
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
)
??
TextStyle
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
),
style:
style
?.
copyWith
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
)
??
TextStyle
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
),
);
},
);
...
...
@@ -620,6 +616,7 @@ class LatexMath extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
p0
=
exp
.
firstMatch
(
text
.
trim
());
p0
?.
group
(
0
);
...
...
@@ -641,8 +638,7 @@ class LatexMath extends InlineMd {
options:
MathOptions
(
sizeUnderTextStyle:
MathSize
.
large
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurface
,
fontSize:
style
?.
fontSize
??
Theme
.
of
(
context
).
textTheme
.
bodyMedium
?.
fontSize
,
fontSize:
style
?.
fontSize
??
Theme
.
of
(
context
).
textTheme
.
bodyMedium
?.
fontSize
,
mathFontOptions:
FontOptions
(
fontFamily:
"Main"
,
fontWeight:
style
?.
fontWeight
??
FontWeight
.
normal
,
...
...
@@ -659,9 +655,7 @@ class LatexMath extends InlineMd {
return
Text
(
workaround
(
mathText
),
textDirection:
textDirection
,
style:
style
?.
copyWith
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
)
??
TextStyle
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
),
style:
style
?.
copyWith
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
)
??
TextStyle
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
),
);
},
),
...
...
@@ -683,6 +677,7 @@ class ItalicMd extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
TextSpan
(
...
...
@@ -694,6 +689,7 @@ class ItalicMd extends InlineMd {
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
,
),
style:
(
style
??
const
TextStyle
()).
copyWith
(
fontStyle:
FontStyle
.
italic
),
);
...
...
@@ -714,6 +710,7 @@ class ATagMd extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
if
(
match
?[
1
]
==
null
&&
match
?[
2
]
==
null
)
{
...
...
@@ -759,13 +756,13 @@ class ImageMd extends InlineMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
double
?
height
;
double
?
width
;
if
(
match
?[
1
]
!=
null
)
{
var
size
=
RegExp
(
r"^([0-9]+)?x?([0-9]+)?"
)
.
firstMatch
(
match
![
1
].
toString
().
trim
());
var
size
=
RegExp
(
r"^([0-9]+)?x?([0-9]+)?"
).
firstMatch
(
match
![
1
].
toString
().
trim
());
width
=
double
.
tryParse
(
size
?[
1
]?.
toString
().
trim
()
??
'a'
);
height
=
double
.
tryParse
(
size
?[
2
]?.
toString
().
trim
()
??
'a'
);
}
...
...
@@ -778,16 +775,12 @@ class ImageMd extends InlineMd {
image:
NetworkImage
(
"
${match?[2]}
"
,
),
loadingBuilder:
(
BuildContext
context
,
Widget
child
,
ImageChunkEvent
?
loadingProgress
)
{
loadingBuilder:
(
BuildContext
context
,
Widget
child
,
ImageChunkEvent
?
loadingProgress
)
{
if
(
loadingProgress
==
null
)
{
return
child
;
}
return
CustomImageLoading
(
progress:
loadingProgress
.
expectedTotalBytes
!=
null
?
loadingProgress
.
cumulativeBytesLoaded
/
loadingProgress
.
expectedTotalBytes
!
:
1
,
progress:
loadingProgress
.
expectedTotalBytes
!=
null
?
loadingProgress
.
cumulativeBytesLoaded
/
loadingProgress
.
expectedTotalBytes
!
:
1
,
);
},
fit:
BoxFit
.
fill
,
...
...
@@ -811,15 +804,12 @@ class TableMd extends BlockMd {
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
final
List
<
Map
<
int
,
String
>>
value
=
text
.
split
(
'
\n
'
)
.
map
<
Map
<
int
,
String
>>(
(
e
)
=>
e
.
split
(
'|'
)
.
where
((
element
)
=>
element
.
isNotEmpty
)
.
toList
()
.
asMap
(),
(
e
)
=>
e
.
split
(
'|'
).
where
((
element
)
=>
element
.
isNotEmpty
).
toList
().
asMap
(),
)
.
toList
();
bool
heading
=
RegExp
(
...
...
@@ -850,9 +840,7 @@ class TableMd extends BlockMd {
(
entry
)
=>
TableRow
(
decoration:
(
heading
)
?
BoxDecoration
(
color:
(
entry
.
key
==
0
)
?
Theme
.
of
(
context
).
colorScheme
.
surfaceVariant
:
null
,
color:
(
entry
.
key
==
0
)
?
Theme
.
of
(
context
).
colorScheme
.
surfaceVariant
:
null
,
)
:
null
,
children:
List
.
generate
(
...
...
@@ -860,15 +848,13 @@ class TableMd extends BlockMd {
(
index
)
{
var
e
=
entry
.
value
;
String
data
=
e
[
index
]
??
""
;
if
(
RegExp
(
r"^--+$"
).
hasMatch
(
data
.
trim
())
||
data
.
trim
().
isEmpty
)
{
if
(
RegExp
(
r"^--+$"
).
hasMatch
(
data
.
trim
())
||
data
.
trim
().
isEmpty
)
{
return
const
SizedBox
();
}
return
Center
(
child:
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8
,
vertical:
4
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8
,
vertical:
4
),
child:
MdWidget
(
(
e
[
index
]
??
""
).
trim
(),
textDirection:
textDirection
,
...
...
@@ -909,13 +895,14 @@ class CodeBlockMd extends BlockMd {
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
,
)
{
String
codes
=
exp
.
firstMatch
(
text
)?[
2
]
??
""
;
String
name
=
exp
.
firstMatch
(
text
)?[
1
]
??
""
;
codes
=
codes
.
replaceAll
(
r"```"
,
""
).
trim
();
return
Padding
(
padding:
const
EdgeInsets
.
all
(
16.0
),
child:
CodeField
(
name:
name
,
codes:
codes
),
child:
codeBuilder
!=
null
?
codeBuilder
(
context
,
codes
)
:
CodeField
(
name:
name
,
codes:
codes
),
);
}
}
...
...
@@ -944,8 +931,7 @@ class _CodeFieldState extends State<CodeField> {
Row
(
children:
[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
16.0
,
vertical:
8
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
16.0
,
vertical:
8
),
child:
Text
(
widget
.
name
),
),
const
Spacer
(),
...
...
@@ -957,8 +943,7 @@ class _CodeFieldState extends State<CodeField> {
),
),
onPressed:
()
async
{
await
Clipboard
.
setData
(
ClipboardData
(
text:
widget
.
codes
))
.
then
((
value
)
{
await
Clipboard
.
setData
(
ClipboardData
(
text:
widget
.
codes
)).
then
((
value
)
{
setState
(()
{
_copied
=
true
;
});
...
...
gpt_markdown/lib/md_widget.dart
View file @
f92a04d
...
...
@@ -5,16 +5,19 @@ import 'package:gpt_markdown/markdown_component.dart';
/// It creates a markdown widget closed to each other.
class
MdWidget
extends
StatelessWidget
{
const
MdWidget
(
this
.
exp
,
{
super
.
key
,
this
.
style
,
this
.
textDirection
=
TextDirection
.
ltr
,
this
.
onLinkTab
,
this
.
textAlign
,
this
.
textScaleFactor
,
this
.
latexWorkaround
,
this
.
latexBuilder
,
this
.
followLinkColor
=
false
});
const
MdWidget
(
this
.
exp
,
{
super
.
key
,
this
.
style
,
this
.
textDirection
=
TextDirection
.
ltr
,
this
.
onLinkTab
,
this
.
textAlign
,
this
.
textScaleFactor
,
this
.
latexWorkaround
,
this
.
latexBuilder
,
this
.
followLinkColor
=
false
,
this
.
codeBuilder
,
});
final
String
exp
;
final
TextDirection
textDirection
;
final
TextStyle
?
style
;
...
...
@@ -24,6 +27,7 @@ class MdWidget extends StatelessWidget {
final
String
Function
(
String
tex
)?
latexWorkaround
;
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
;
final
bool
followLinkColor
;
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
codeBuilder
;
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -46,6 +50,7 @@ class MdWidget extends StatelessWidget {
onLinkTab
,
latexWorkaround
,
latexBuilder
,
codeBuilder
,
),
);
return
Text
.
rich
(
...
...
Please
register
or
login
to post a comment