saminsohag

`IndentMd` and `BlockQuote` fixed.

## 1.0.16
* `IndentMd` and `BlockQuote` fixed.
## 1.0.15
* Performance improvements.
... ...
... ... @@ -126,7 +126,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.9"
version: "1.0.15"
http:
dependency: transitive
description:
... ...
... ... @@ -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 [IndentWidget] widget is used to create a visual indent in the UI.
/// The [BlockQuoteWidget] 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,
... ...
... ... @@ -128,6 +128,7 @@ class GptMarkdown extends StatelessWidget {
return ClipRRect(
child: MdWidget(
tex,
true,
config: GptMarkdownConfig(
textDirection: textDirection,
style: style,
... ...
... ... @@ -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: IndentWidget(
child: BlockQuoteWidget(
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,
),
),
... ...
... ... @@ -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(
... ...
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.15
version: 1.0.16
homepage: https://github.com/Infinitix-LLC/gpt_markdown
environment:
... ...