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-05-17 14:26:55 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5f5e5e6f729130f5484e49daa578fe6125f2e5be
5f5e5e6f
1 parent
45fd08d6
performance improvements
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
23 deletions
CHANGELOG.md
example/lib/main.dart
lib/custom_widgets/markdown_config.dart
lib/gpt_markdown.dart
lib/markdown_component.dart
lib/md_widget.dart
pubspec.yaml
CHANGELOG.md
View file @
5f5e5e6
## 1.0.19
*
Performance improvements.
## 1.0.18
*
dollarSignForLatex is added and by default it is false.
...
...
example/lib/main.dart
View file @
5f5e5e6
...
...
@@ -76,6 +76,16 @@ class _MyHomePageState extends State<MyHomePage> {
TextDirection
_direction
=
TextDirection
.
ltr
;
final
TextEditingController
_controller
=
TextEditingController
(
text:
r''
'
This is a sample markdown document.
* **bold**
* *italic*
* **_bold and italic_**
* ~~strikethrough~~
* `code`
* [link](https://www.google.com) 
```markdown
# Complex Markdown Document for Testing
...
...
lib/custom_widgets/markdown_config.dart
View file @
5f5e5e6
...
...
@@ -198,4 +198,27 @@ class GptMarkdownConfig {
overflow:
overflow
,
);
}
/// A method to check if the configuration is the same.
bool
isSame
(
GptMarkdownConfig
other
)
{
return
style
==
other
.
style
&&
textAlign
==
other
.
textAlign
&&
textScaler
==
other
.
textScaler
&&
maxLines
==
other
.
maxLines
&&
overflow
==
other
.
overflow
&&
followLinkColor
==
other
.
followLinkColor
&&
// latexWorkaround == other.latexWorkaround &&
// components == other.components &&
// inlineComponents == other.inlineComponents &&
// latexBuilder == other.latexBuilder &&
// sourceTagBuilder == other.sourceTagBuilder &&
// codeBuilder == other.codeBuilder &&
// orderedListBuilder == other.orderedListBuilder &&
// unOrderedListBuilder == other.unOrderedListBuilder &&
// linkBuilder == other.linkBuilder &&
// imageBuilder == other.imageBuilder &&
// highlightBuilder == other.highlightBuilder &&
// onLinkTab == other.onLinkTab &&
textDirection
==
other
.
textDirection
;
}
}
...
...
lib/gpt_markdown.dart
View file @
5f5e5e6
...
...
@@ -179,6 +179,7 @@ class GptMarkdown extends StatelessWidget {
// tex = _removeExtraLinesInsideBlockLatex(tex);
return
ClipRRect
(
child:
MdWidget
(
context
,
tex
,
true
,
config:
GptMarkdownConfig
(
...
...
lib/markdown_component.dart
View file @
5f5e5e6
...
...
@@ -294,7 +294,7 @@ class CheckBoxMd extends BlockMd {
return
CustomCb
(
value:
(
"
${match?[1]}
"
==
"x"
),
textDirection:
config
.
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
false
,
config:
config
),
child:
MdWidget
(
context
,
"
${match?[2]}
"
,
false
,
config:
config
),
);
}
}
...
...
@@ -315,7 +315,7 @@ class RadioButtonMd extends BlockMd {
return
CustomRb
(
value:
(
"
${match?[1]}
"
==
"x"
),
textDirection:
config
.
textDirection
,
child:
MdWidget
(
"
${match?[2]}
"
,
false
,
config:
config
),
child:
MdWidget
(
context
,
"
${match?[2]}
"
,
false
,
config:
config
),
);
}
}
...
...
@@ -394,7 +394,7 @@ class UnOrderedList extends BlockMd {
)
{
var
match
=
this
.
exp
.
firstMatch
(
text
);
var
child
=
MdWidget
(
"
${match?[1]?.trim()}
"
,
true
,
config:
config
);
var
child
=
MdWidget
(
context
,
"
${match?[1]?.trim()}
"
,
true
,
config:
config
);
return
config
.
unOrderedListBuilder
?.
call
(
context
,
...
...
@@ -432,7 +432,7 @@ class OrderedList extends BlockMd {
var
no
=
"
${match?[1]}
"
;
var
child
=
MdWidget
(
"
${match?[2]?.trim()}
"
,
true
,
config:
config
);
var
child
=
MdWidget
(
context
,
"
${match?[2]?.trim()}
"
,
true
,
config:
config
);
return
config
.
orderedListBuilder
?.
call
(
context
,
no
,
...
...
@@ -971,6 +971,7 @@ class TableMd extends BlockMd {
vertical:
4
,
),
child:
MdWidget
(
context
,
(
e
[
index
]
??
""
).
trim
(),
false
,
config:
config
,
...
...
lib/md_widget.dart
View file @
5f5e5e6
part of
'gpt_markdown.dart'
;
/// It creates a markdown widget closed to each other.
class
MdWidget
extends
State
less
Widget
{
class
MdWidget
extends
State
ful
Widget
{
const
MdWidget
(
this
.
context
,
this
.
exp
,
this
.
includeGlobalComponents
,
{
super
.
key
,
...
...
@@ -11,6 +12,7 @@ class MdWidget extends StatelessWidget {
/// The expression to be displayed.
final
String
exp
;
final
BuildContext
context
;
/// Whether to include global components.
final
bool
includeGlobalComponents
;
...
...
@@ -19,25 +21,46 @@ class MdWidget extends StatelessWidget {
final
GptMarkdownConfig
config
;
@override
Widget
build
(
BuildContext
context
)
{
List
<
InlineSpan
>
list
=
MarkdownComponent
.
generate
(
State
<
MdWidget
>
createState
()
=>
_MdWidgetState
();
}
class
_MdWidgetState
extends
State
<
MdWidget
>
{
List
<
InlineSpan
>
list
=
[];
@override
void
initState
()
{
super
.
initState
();
list
=
MarkdownComponent
.
generate
(
widget
.
context
,
widget
.
exp
,
widget
.
config
,
widget
.
includeGlobalComponents
,
);
}
@override
void
didUpdateWidget
(
covariant
MdWidget
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
oldWidget
.
exp
!=
widget
.
exp
||
!
oldWidget
.
config
.
isSame
(
widget
.
config
))
{
list
=
MarkdownComponent
.
generate
(
context
,
exp
,
// .replaceAllMapped(
// RegExp(
// r"\\\[(.*?)\\\]|(\\begin.*?\\end{.*?})",
// multiLine: true,
// dotAll: true,
// ), (match) {
// //
// String body = (match[1] ?? match[2])?.replaceAll("\n", " ") ?? "";
// return "\\[$body\\]";
// }),
config
,
includeGlobalComponents
,
widget
.
exp
,
widget
.
config
,
widget
.
includeGlobalComponents
,
);
return
config
.
getRich
(
TextSpan
(
children:
list
,
style:
config
.
style
?.
copyWith
()),
}
}
@override
Widget
build
(
BuildContext
context
)
{
// List<InlineSpan> list = MarkdownComponent.generate(
// context,
// widget.exp,
// widget.config,
// widget.includeGlobalComponents,
// );
return
widget
.
config
.
getRich
(
TextSpan
(
children:
list
,
style:
widget
.
config
.
style
?.
copyWith
()),
);
}
}
...
...
pubspec.yaml
View file @
5f5e5e6
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
8
version
:
1.0.1
9
homepage
:
https://github.com/Infinitix-LLC/gpt_markdown
environment
:
...
...
Please
register
or
login
to post a comment