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-18 15:33:23 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
63469c829e92707518eb38432c67b366a3f26cf1
63469c82
1 parent
4a88e5f1
block quote support improved
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
14 deletions
CHANGELOG.md
lib/custom_widgets/indent_widget.dart
lib/markdown_component.dart
CHANGELOG.md
View file @
63469c8
...
...
@@ -2,6 +2,7 @@
*
`IndentMd` and `BlockQuote`
fixed.
*
Baseline of bloc type component is fixed.
*
block quote support improved.
## 1.0.15
...
...
lib/custom_widgets/indent_widget.dart
View file @
63469c8
...
...
@@ -12,6 +12,7 @@ class BlockQuoteWidget extends StatelessWidget {
required
this
.
child
,
required
this
.
direction
,
required
this
.
color
,
this
.
width
=
3
,
});
/// The child widget to be indented.
...
...
@@ -23,29 +24,39 @@ class BlockQuoteWidget extends StatelessWidget {
/// The color of the indent.
final
Color
color
;
/// The width of the indent.
final
double
width
;
@override
Widget
build
(
BuildContext
context
)
{
return
CustomPaint
(
foregroundPainter:
IndentPainter
(
color
,
direction
),
return
Row
(
children:
[
Expanded
(
child:
CustomPaint
(
foregroundPainter:
BlockQuotePainter
(
color
,
direction
,
width
),
child:
child
,
),
),
],
);
}
}
/// A custom painter that draws an indent on a canvas.
///
/// The [
Indent
Painter] class extends CustomPainter and is responsible for
/// The [
BlockQuote
Painter] class extends CustomPainter and is responsible for
/// painting the indent on a canvas. It takes a [color] and [direction] parameter
/// and uses them to draw an indent in the UI.
class
IndentPainter
extends
CustomPainter
{
IndentPainter
(
this
.
color
,
this
.
direction
);
class
BlockQuotePainter
extends
CustomPainter
{
BlockQuotePainter
(
this
.
color
,
this
.
direction
,
this
.
width
);
final
Color
color
;
final
TextDirection
direction
;
final
double
width
;
@override
void
paint
(
Canvas
canvas
,
Size
size
)
{
var
left
=
direction
==
TextDirection
.
ltr
;
var
start
=
left
?
0.0
:
size
.
width
-
4
;
var
rect
=
Rect
.
fromLTWH
(
start
,
0
,
4
,
size
.
height
);
var
start
=
left
?
0.0
:
size
.
width
-
width
;
var
rect
=
Rect
.
fromLTWH
(
start
,
0
,
width
,
size
.
height
);
var
paint
=
Paint
()..
color
=
color
;
canvas
.
drawRect
(
rect
,
paint
);
}
...
...
lib/markdown_component.dart
View file @
63469c8
...
...
@@ -322,7 +322,7 @@ class BlockQuote extends InlineMd {
@override
RegExp
get
exp
=>
// RegExp(r"(?<=\n\n)(\ +)(.+?)(?=\n\n)", dotAll: true, multiLine: true);
RegExp
(
r"
^>([^\n]+)$
"
,
dotAll:
true
,
multiLine:
true
);
RegExp
(
r"
(?:(?:^|\n)\ *>[^\n]+)+
"
,
dotAll:
true
,
multiLine:
true
);
@override
InlineSpan
span
(
...
...
@@ -331,9 +331,20 @@ class BlockQuote extends InlineMd {
final
GptMarkdownConfig
config
,
)
{
var
match
=
exp
.
firstMatch
(
text
);
var
data
=
"
${match?[1]}
"
.
trim
();
// data = data.replaceAll(RegExp(r'\n\ {' '$spaces' '}'), '\n').trim();
data
=
data
.
trim
();
var
dataBuilder
=
StringBuffer
();
var
m
=
match
?[
0
]
??
''
;
for
(
var
each
in
m
.
split
(
'
\n
'
))
{
if
(
each
.
startsWith
(
RegExp
(
r'\ *>'
)))
{
var
subString
=
each
.
trimLeft
().
substring
(
1
);
if
(
subString
.
startsWith
(
' '
))
{
subString
=
subString
.
substring
(
1
);
}
dataBuilder
.
writeln
(
subString
);
}
else
{
dataBuilder
.
writeln
(
each
);
}
}
var
data
=
dataBuilder
.
toString
().
trim
();
var
child
=
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
data
,
config
,
true
),
);
...
...
@@ -347,8 +358,9 @@ class BlockQuote extends InlineMd {
child:
BlockQuoteWidget
(
color:
Theme
.
of
(
context
).
colorScheme
.
onSurfaceVariant
,
direction:
config
.
textDirection
,
width:
3
,
child:
Padding
(
padding:
const
EdgeInsetsDirectional
.
only
(
start:
10
.0
),
padding:
const
EdgeInsetsDirectional
.
only
(
start:
8
.0
),
child:
config
.
getRich
(
child
),
),
),
...
...
@@ -873,7 +885,7 @@ class ImageMd extends InlineMd {
class
TableMd
extends
BlockMd
{
@override
String
get
expString
=>
(
r"(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?)
)(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?))
)+)$"
);
(
r"(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?)
\ *)(\n\ *(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?))\ *
)+)$"
);
@override
Widget
build
(
BuildContext
context
,
...
...
@@ -886,6 +898,7 @@ class TableMd extends BlockMd {
.
map
<
Map
<
int
,
String
>>(
(
e
)
=>
e
.
trim
()
.
split
(
'|'
)
.
where
((
element
)
=>
element
.
isNotEmpty
)
.
toList
()
...
...
@@ -939,7 +952,7 @@ class TableMd extends BlockMd {
children:
List
.
generate
(
maxCol
,
(
index
)
{
var
e
=
entry
.
value
;
String
data
=
e
[
index
]
??
""
;
if
(
RegExp
(
r"^
--+
$"
).
hasMatch
(
data
.
trim
())
||
if
(
RegExp
(
r"^
:?--+:?
$"
).
hasMatch
(
data
.
trim
())
||
data
.
trim
().
isEmpty
)
{
return
const
SizedBox
();
}
...
...
Please
register
or
login
to post a comment