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
saminsohag
2023-04-08 07:09:14 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
31d3d5dad14f9a982e37b761b644f01cb5c5572c
31d3d5da
1 parent
65ffce44
bug fixed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
49 deletions
tex_markdown/example/lib/main.dart
tex_markdown/lib/markdown_component.dart
tex_markdown/lib/tex_markdown.dart
tex_markdown/example/lib/main.dart
View file @
31d3d5d
...
...
@@ -106,14 +106,19 @@ $hello$
AnimatedBuilder
(
animation:
_controller
,
builder:
(
context
,
_
)
{
return
TexMarkdown
(
_controller
.
text
,
onLinkTab:
(
url
,
title
)
{
log
(
title
,
name:
"title"
);
log
(
url
,
name:
"url"
);
},
style:
const
TextStyle
(
color:
Colors
.
green
,
return
Material
(
shape:
const
RoundedRectangleBorder
(
side:
BorderSide
(
width:
1
),
),
child:
TexMarkdown
(
_controller
.
text
,
onLinkTab:
(
url
,
title
)
{
log
(
title
,
name:
"title"
);
log
(
url
,
name:
"url"
);
},
style:
const
TextStyle
(
color:
Colors
.
green
,
),
),
);
}),
...
...
tex_markdown/lib/markdown_component.dart
View file @
31d3d5d
...
...
@@ -44,40 +44,28 @@ abstract class MarkdownComponent {
TextStyle
?
style
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
)
{
List
<
Widget
>
children
=
[];
List
<
InlineSpan
>
spans
=
[];
text
.
split
(
RegExp
(
r"\n+"
)).
forEach
(
(
element
)
{
for
(
var
each
in
components
)
{
if
(
each
.
exp
.
hasMatch
(
element
.
trim
()))
{
if
(
each
is
InlineMd
)
{
if
(
spans
.
isNotEmpty
)
{
spans
.
add
(
TextSpan
(
text:
" "
,
style:
style
,
),
);
}
spans
.
add
(
each
.
inlineSpan
(
spans
.
add
(
each
.
span
(
context
,
element
,
style
,
onLinkTab
,
));
spans
.
add
(
TextSpan
(
text:
" "
,
style:
style
,
),
);
}
else
{
if
(
spans
.
isNotEmpty
)
{
children
.
add
(
Text
.
rich
(
TextSpan
(
children:
List
.
from
(
spans
)),
textAlign:
TextAlign
.
left
,
),
);
spans
.
clear
();
}
if
(
each
is
BlockMd
)
{
children
.
add
(
each
.
build
(
context
,
element
,
style
,
onLinkTab
),
spans
.
add
(
each
.
span
(
context
,
element
,
style
,
onLinkTab
),
);
}
}
...
...
@@ -86,22 +74,21 @@ abstract class MarkdownComponent {
}
},
);
if
(
spans
.
isNotEmpty
)
{
children
.
add
(
Text
.
rich
(
TextSpan
(
children:
List
.
from
(
spans
),
),
textAlign:
TextAlign
.
left
,
),
);
}
return
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
children
,
return
Text
.
rich
(
TextSpan
(
children:
List
.
from
(
spans
),
),
textAlign:
TextAlign
.
left
,
);
}
InlineSpan
span
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
);
RegExp
get
exp
;
bool
get
inline
;
}
...
...
@@ -110,7 +97,9 @@ abstract class MarkdownComponent {
abstract
class
InlineMd
extends
MarkdownComponent
{
@override
bool
get
inline
=>
true
;
InlineSpan
inlineSpan
(
@override
InlineSpan
span
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
...
...
@@ -123,6 +112,21 @@ abstract class InlineMd extends MarkdownComponent {
abstract
class
BlockMd
extends
MarkdownComponent
{
@override
bool
get
inline
=>
false
;
@override
InlineSpan
span
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
)
{
return
WidgetSpan
(
child:
Align
(
alignment:
Alignment
.
centerLeft
,
child:
build
(
context
,
text
,
style
,
onLinkTab
),
),
);
}
Widget
build
(
BuildContext
context
,
String
text
,
...
...
@@ -409,7 +413,7 @@ class BoldMd extends InlineMd {
final
RegExp
exp
=
RegExp
(
r"^\*{2}(([\S^\*].*)?[\S^\*])\*{2}$"
);
@override
InlineSpan
inlineS
pan
(
InlineSpan
s
pan
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
...
...
@@ -443,7 +447,7 @@ class ItalicMd extends InlineMd {
final
RegExp
exp
=
RegExp
(
r"^\*{1}(([\S^\*].*)?[\S^\*])\*{1}$"
);
@override
InlineSpan
inlineS
pan
(
InlineSpan
s
pan
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
...
...
@@ -475,7 +479,7 @@ class ATagMd extends InlineMd {
final
RegExp
exp
=
RegExp
(
r"^\[([^\s\*].*[^\s]?)?\]\(([^\s\*]+)?\)$"
);
@override
InlineSpan
inlineS
pan
(
InlineSpan
s
pan
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
...
...
@@ -520,7 +524,7 @@ class ImageMd extends InlineMd {
final
RegExp
exp
=
RegExp
(
r"^\!\[([^\s].*[^\s]?)?\]\(([^\s]+)\)$"
);
@override
InlineSpan
inlineS
pan
(
InlineSpan
s
pan
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
...
...
@@ -578,7 +582,7 @@ class TextMd extends InlineMd {
final
RegExp
exp
=
RegExp
(
".*"
);
@override
InlineSpan
inlineS
pan
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
InlineSpan
s
pan
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
void
Function
(
String
url
,
String
title
)?
onLinkTab
)
{
return
WidgetSpan
(
alignment:
PlaceholderAlignment
.
baseline
,
...
...
tex_markdown/lib/tex_markdown.dart
View file @
31d3d5d
...
...
@@ -36,7 +36,7 @@ class TexMarkdown extends StatelessWidget {
)
.
map
<
Widget
>(
(
e
)
=>
Padding
(
padding:
const
EdgeInsets
.
all
(
4
),
padding:
const
EdgeInsets
.
symmetric
(
vertical:
4
,
horizontal:
4
),
child:
MdWidget
(
e
,
style:
style
,
...
...
Please
register
or
login
to post a comment