saminsohag

block quote support improved

... ... @@ -2,6 +2,7 @@
* `IndentMd` and `BlockQuote` fixed.
* Baseline of bloc type component is fixed.
* block quote support improved.
## 1.0.15
... ...
... ... @@ -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),
child: child,
return Row(
children: [
Expanded(
child: CustomPaint(
foregroundPainter: BlockQuotePainter(color, direction, width),
child: child,
),
),
],
);
}
}
/// A custom painter that draws an indent on a canvas.
///
/// The [IndentPainter] class extends CustomPainter and is responsible for
/// The [BlockQuotePainter] 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);
}
... ...
... ... @@ -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();
}
... ...