saminsohag

performance improvements

## 1.0.19
* Performance improvements.
## 1.0.18
* dollarSignForLatex is added and by default it is false.
... ...
... ... @@ -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) ![image](https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png)
```markdown
# Complex Markdown Document for Testing
... ...
... ... @@ -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;
}
}
... ...
... ... @@ -179,6 +179,7 @@ class GptMarkdown extends StatelessWidget {
// tex = _removeExtraLinesInsideBlockLatex(tex);
return ClipRRect(
child: MdWidget(
context,
tex,
true,
config: GptMarkdownConfig(
... ...
... ... @@ -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,
... ...
part of 'gpt_markdown.dart';
/// It creates a markdown widget closed to each other.
class MdWidget extends StatelessWidget {
class MdWidget extends StatefulWidget {
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()),
);
}
}
... ...
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.18
version: 1.0.19
homepage: https://github.com/Infinitix-LLC/gpt_markdown
environment:
... ...