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
2025-03-17 22:29:26 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4b793c4f5783a7363d534472f3170f48646def32
4b793c4f
1 parent
842dbe59
`IndentMd` and `BlockQuote` fixed.
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
109 additions
and
24 deletions
CHANGELOG.md
example/pubspec.lock
lib/custom_widgets/indent_widget.dart
lib/gpt_markdown.dart
lib/markdown_component.dart
lib/md_widget.dart
pubspec.yaml
CHANGELOG.md
View file @
4b793c4
## 1.0.16
*
`IndentMd` and `BlockQuote`
fixed.
## 1.0.15
*
Performance improvements.
...
...
example/pubspec.lock
View file @
4b793c4
...
...
@@ -126,7 +126,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.
9
"
version: "1.0.
15
"
http:
dependency: transitive
description:
...
...
lib/custom_widgets/indent_widget.dart
View file @
4b793c4
...
...
@@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
/// A custom widget that adds an indent to the left or right of its child.
///
/// The [
Indent
Widget] widget is used to create a visual indent in the UI.
/// The [
BlockQuote
Widget] widget is used to create a visual indent in the UI.
/// It takes a [child] parameter which is the content of the widget,
/// a [direction] parameter which specifies the direction of the indent,
/// and a [color] parameter to set the color of the indent.
class
IndentWidget
extends
StatelessWidget
{
const
IndentWidget
({
class
BlockQuoteWidget
extends
StatelessWidget
{
const
BlockQuoteWidget
({
super
.
key
,
required
this
.
child
,
required
this
.
direction
,
...
...
lib/gpt_markdown.dart
View file @
4b793c4
...
...
@@ -128,6 +128,7 @@ class GptMarkdown extends StatelessWidget {
return
ClipRRect
(
child:
MdWidget
(
tex
,
true
,
config:
GptMarkdownConfig
(
textDirection:
textDirection
,
style:
style
,
...
...
lib/markdown_component.dart
View file @
4b793c4
...
...
@@ -5,7 +5,7 @@ abstract class MarkdownComponent {
static
final
List
<
MarkdownComponent
>
components
=
[
CodeBlockMd
(),
NewLines
(),
IndentMd
(),
BlockQuote
(),
ImageMd
(),
ATagMd
(),
TableMd
(),
...
...
@@ -20,7 +20,20 @@ abstract class MarkdownComponent {
ItalicMd
(),
LatexMath
(),
LatexMathMultiLine
(),
HighlightedText
(),
SourceTag
(),
IndentMd
(),
];
static
final
List
<
MarkdownComponent
>
inlineComponents
=
[
ImageMd
(),
ATagMd
(),
TableMd
(),
StrikeMd
(),
BoldMd
(),
ItalicMd
(),
LatexMath
(),
LatexMathMultiLine
(),
HighlightedText
(),
SourceTag
(),
];
...
...
@@ -30,10 +43,14 @@ abstract class MarkdownComponent {
BuildContext
context
,
String
text
,
final
GptMarkdownConfig
config
,
bool
includeGlobalComponents
,
)
{
var
components
=
includeGlobalComponents
?
MarkdownComponent
.
components
:
MarkdownComponent
.
inlineComponents
;
List
<
InlineSpan
>
spans
=
[];
List
<
String
>
regexes
=
components
.
map
<
String
>((
e
)
=>
e
.
exp
.
pattern
).
toList
();
Iterable
<
String
>
regexes
=
components
.
map
<
String
>((
e
)
=>
e
.
exp
.
pattern
);
final
combinedRegex
=
RegExp
(
regexes
.
join
(
"|"
),
multiLine:
true
,
...
...
@@ -46,7 +63,7 @@ abstract class MarkdownComponent {
for
(
var
each
in
components
)
{
var
p
=
each
.
exp
.
pattern
;
var
exp
=
RegExp
(
'^
$p
'
,
'^
$p
\$
'
,
multiLine:
each
.
exp
.
isMultiLine
,
dotAll:
each
.
exp
.
isDotAll
,
);
...
...
@@ -133,7 +150,11 @@ abstract class BlockMd extends MarkdownComponent {
var
child
=
build
(
context
,
text
,
config
);
length
=
min
(
length
,
4
);
if
(
length
>
0
)
{
child
=
UnorderedListView
(
spacing:
length
*
1.0
,
child:
child
);
child
=
UnorderedListView
(
spacing:
length
*
1.0
,
textDirection:
config
.
textDirection
,
child:
child
,
);
}
return
WidgetSpan
(
child:
child
,
alignment:
PlaceholderAlignment
.
middle
);
}
...
...
@@ -145,6 +166,40 @@ abstract class BlockMd extends MarkdownComponent {
);
}
/// Indent component
class
IndentMd
extends
BlockMd
{
@override
String
get
expString
=>
(
r"^(\ \ +)([^\n]+)$"
);
@override
Widget
build
(
BuildContext
context
,
String
text
,
final
GptMarkdownConfig
config
,
)
{
var
match
=
this
.
exp
.
firstMatch
(
text
);
var
conf
=
config
.
copyWith
();
return
Directionality
(
textDirection:
config
.
textDirection
,
child:
Row
(
children:
[
Expanded
(
child:
config
.
getRich
(
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
match
?[
2
]?.
trim
()
??
""
,
conf
,
false
,
),
),
),
),
],
),
);
}
}
/// Heading component
class
HTag
extends
BlockMd
{
@override
...
...
@@ -174,6 +229,7 @@ class HTag extends BlockMd {
context
,
"
${match.namedGroup('data')}
"
,
conf
,
false
,
)),
if
(
match
.
namedGroup
(
'hash'
)!.
length
==
1
)
...[
const
TextSpan
(
...
...
@@ -205,8 +261,12 @@ class NewLines extends InlineMd {
final
GptMarkdownConfig
config
,
)
{
return
TextSpan
(
text:
"
\n\n\n\n
"
,
style:
TextStyle
(
fontSize:
6
,
color:
config
.
style
?.
color
),
text:
"
\n\n
"
,
style:
TextStyle
(
fontSize:
config
.
style
?.
fontSize
??
14
,
height:
1.15
,
color:
config
.
style
?.
color
,
),
);
}
}
...
...
@@ -246,7 +306,7 @@ class CheckBoxMd extends BlockMd {
return
CustomCb
(
value:
(
"
${match?[1]}
"
==
"x"
),
textDirection:
config
.
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
config:
config
),
child:
MdWidget
(
"
${match?[2]}
"
,
false
,
config:
config
),
);
}
}
...
...
@@ -267,13 +327,13 @@ class RadioButtonMd extends BlockMd {
return
CustomRb
(
value:
(
"
${match?[1]}
"
==
"x"
),
textDirection:
config
.
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
config:
config
),
child:
MdWidget
(
"
${match?[2]}
"
,
false
,
config:
config
),
);
}
}
/// Indent
class
IndentMd
extends
InlineMd
{
/// Block quote component
class
BlockQuote
extends
InlineMd
{
@override
bool
get
inline
=>
false
;
@override
...
...
@@ -292,7 +352,7 @@ class IndentMd extends InlineMd {
// data = data.replaceAll(RegExp(r'\n\ {' '$spaces' '}'), '\n').trim();
data
=
data
.
trim
();
var
child
=
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
data
,
config
),
children:
MarkdownComponent
.
generate
(
context
,
data
,
config
,
true
),
);
return
TextSpan
(
children:
[
...
...
@@ -301,7 +361,7 @@ class IndentMd extends InlineMd {
textDirection:
config
.
textDirection
,
child:
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
vertical:
2
),
child:
Indent
Widget
(
child:
BlockQuote
Widget
(
color:
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
,
direction:
config
.
textDirection
,
child:
Padding
(
...
...
@@ -330,7 +390,7 @@ class UnOrderedList extends BlockMd {
)
{
var
match
=
this
.
exp
.
firstMatch
(
text
);
var
child
=
MdWidget
(
"
${match?[1]?.trim()}
"
,
config:
config
);
var
child
=
MdWidget
(
"
${match?[1]?.trim()}
"
,
false
,
config:
config
);
return
config
.
unOrderedListBuilder
?.
call
(
context
,
...
...
@@ -368,7 +428,7 @@ class OrderedList extends BlockMd {
var
no
=
"
${match?[1]}
"
;
var
child
=
MdWidget
(
"
${match?[2]?.trim()}
"
,
config:
config
);
var
child
=
MdWidget
(
"
${match?[2]?.trim()}
"
,
false
,
config:
config
);
return
config
.
orderedListBuilder
?.
call
(
context
,
no
,
...
...
@@ -450,7 +510,12 @@ class BoldMd extends InlineMd {
const
TextStyle
(
fontWeight:
FontWeight
.
bold
),
);
return
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[1]}
"
,
conf
),
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[1]}
"
,
conf
,
false
,
),
style:
conf
.
style
,
);
}
...
...
@@ -476,7 +541,12 @@ class StrikeMd extends InlineMd {
const
TextStyle
(
decoration:
TextDecoration
.
lineThrough
),
);
return
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[1]}
"
,
conf
),
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[1]}
"
,
conf
,
false
,
),
style:
conf
.
style
,
);
}
...
...
@@ -504,7 +574,7 @@ class ItalicMd extends InlineMd {
),
);
return
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
"
$data
"
,
conf
),
children:
MarkdownComponent
.
generate
(
context
,
"
$data
"
,
conf
,
false
),
style:
conf
.
style
,
);
}
...
...
@@ -898,6 +968,7 @@ class TableMd extends BlockMd {
),
child:
MdWidget
(
(
e
[
index
]
??
""
).
trim
(),
false
,
config:
config
,
),
),
...
...
lib/md_widget.dart
View file @
4b793c4
...
...
@@ -2,11 +2,19 @@ part of 'gpt_markdown.dart';
/// It creates a markdown widget closed to each other.
class
MdWidget
extends
StatelessWidget
{
const
MdWidget
(
this
.
exp
,
{
super
.
key
,
required
this
.
config
});
const
MdWidget
(
this
.
exp
,
this
.
includeGlobalComponents
,
{
super
.
key
,
required
this
.
config
,
});
/// The expression to be displayed.
final
String
exp
;
/// Whether to include global components.
final
bool
includeGlobalComponents
;
/// The configuration of the markdown widget.
final
GptMarkdownConfig
config
;
...
...
@@ -28,6 +36,7 @@ class MdWidget extends StatelessWidget {
// return "\\[$body\\]";
// }),
config
,
includeGlobalComponents
,
),
);
return
config
.
getRich
(
...
...
pubspec.yaml
View file @
4b793c4
name
:
gpt_markdown
description
:
"
Powerful
Markdown
&
LaTeX
Renderer
for
Flutter:
Rich
Text,
Math,
Tables,
Links,
and
Text
Selection.
Ideal
for
ChatGPT,
Gemini,
and
more."
version
:
1.0.1
5
version
:
1.0.1
6
homepage
:
https://github.com/Infinitix-LLC/gpt_markdown
environment
:
...
...
Please
register
or
login
to post a comment