saminsohag

block quote support improved

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 * `IndentMd` and `BlockQuote` fixed. 3 * `IndentMd` and `BlockQuote` fixed.
4 * Baseline of bloc type component is fixed. 4 * Baseline of bloc type component is fixed.
  5 +* block quote support improved.
5 6
6 ## 1.0.15 7 ## 1.0.15
7 8
@@ -12,6 +12,7 @@ class BlockQuoteWidget extends StatelessWidget { @@ -12,6 +12,7 @@ class BlockQuoteWidget extends StatelessWidget {
12 required this.child, 12 required this.child,
13 required this.direction, 13 required this.direction,
14 required this.color, 14 required this.color,
  15 + this.width = 3,
15 }); 16 });
16 17
17 /// The child widget to be indented. 18 /// The child widget to be indented.
@@ -23,29 +24,39 @@ class BlockQuoteWidget extends StatelessWidget { @@ -23,29 +24,39 @@ class BlockQuoteWidget extends StatelessWidget {
23 /// The color of the indent. 24 /// The color of the indent.
24 final Color color; 25 final Color color;
25 26
  27 + /// The width of the indent.
  28 + final double width;
  29 +
26 @override 30 @override
27 Widget build(BuildContext context) { 31 Widget build(BuildContext context) {
28 - return CustomPaint(  
29 - foregroundPainter: IndentPainter(color, direction),  
30 - child: child, 32 + return Row(
  33 + children: [
  34 + Expanded(
  35 + child: CustomPaint(
  36 + foregroundPainter: BlockQuotePainter(color, direction, width),
  37 + child: child,
  38 + ),
  39 + ),
  40 + ],
31 ); 41 );
32 } 42 }
33 } 43 }
34 44
35 /// A custom painter that draws an indent on a canvas. 45 /// A custom painter that draws an indent on a canvas.
36 /// 46 ///
37 -/// The [IndentPainter] class extends CustomPainter and is responsible for 47 +/// The [BlockQuotePainter] class extends CustomPainter and is responsible for
38 /// painting the indent on a canvas. It takes a [color] and [direction] parameter 48 /// painting the indent on a canvas. It takes a [color] and [direction] parameter
39 /// and uses them to draw an indent in the UI. 49 /// and uses them to draw an indent in the UI.
40 -class IndentPainter extends CustomPainter {  
41 - IndentPainter(this.color, this.direction); 50 +class BlockQuotePainter extends CustomPainter {
  51 + BlockQuotePainter(this.color, this.direction, this.width);
42 final Color color; 52 final Color color;
43 final TextDirection direction; 53 final TextDirection direction;
  54 + final double width;
44 @override 55 @override
45 void paint(Canvas canvas, Size size) { 56 void paint(Canvas canvas, Size size) {
46 var left = direction == TextDirection.ltr; 57 var left = direction == TextDirection.ltr;
47 - var start = left ? 0.0 : size.width - 4;  
48 - var rect = Rect.fromLTWH(start, 0, 4, size.height); 58 + var start = left ? 0.0 : size.width - width;
  59 + var rect = Rect.fromLTWH(start, 0, width, size.height);
49 var paint = Paint()..color = color; 60 var paint = Paint()..color = color;
50 canvas.drawRect(rect, paint); 61 canvas.drawRect(rect, paint);
51 } 62 }
@@ -322,7 +322,7 @@ class BlockQuote extends InlineMd { @@ -322,7 +322,7 @@ class BlockQuote extends InlineMd {
322 @override 322 @override
323 RegExp get exp => 323 RegExp get exp =>
324 // RegExp(r"(?<=\n\n)(\ +)(.+?)(?=\n\n)", dotAll: true, multiLine: true); 324 // RegExp(r"(?<=\n\n)(\ +)(.+?)(?=\n\n)", dotAll: true, multiLine: true);
325 - RegExp(r"^>([^\n]+)$", dotAll: true, multiLine: true); 325 + RegExp(r"(?:(?:^|\n)\ *>[^\n]+)+", dotAll: true, multiLine: true);
326 326
327 @override 327 @override
328 InlineSpan span( 328 InlineSpan span(
@@ -331,9 +331,20 @@ class BlockQuote extends InlineMd { @@ -331,9 +331,20 @@ class BlockQuote extends InlineMd {
331 final GptMarkdownConfig config, 331 final GptMarkdownConfig config,
332 ) { 332 ) {
333 var match = exp.firstMatch(text); 333 var match = exp.firstMatch(text);
334 - var data = "${match?[1]}".trim();  
335 - // data = data.replaceAll(RegExp(r'\n\ {' '$spaces' '}'), '\n').trim();  
336 - data = data.trim(); 334 + var dataBuilder = StringBuffer();
  335 + var m = match?[0] ?? '';
  336 + for (var each in m.split('\n')) {
  337 + if (each.startsWith(RegExp(r'\ *>'))) {
  338 + var subString = each.trimLeft().substring(1);
  339 + if (subString.startsWith(' ')) {
  340 + subString = subString.substring(1);
  341 + }
  342 + dataBuilder.writeln(subString);
  343 + } else {
  344 + dataBuilder.writeln(each);
  345 + }
  346 + }
  347 + var data = dataBuilder.toString().trim();
337 var child = TextSpan( 348 var child = TextSpan(
338 children: MarkdownComponent.generate(context, data, config, true), 349 children: MarkdownComponent.generate(context, data, config, true),
339 ); 350 );
@@ -347,8 +358,9 @@ class BlockQuote extends InlineMd { @@ -347,8 +358,9 @@ class BlockQuote extends InlineMd {
347 child: BlockQuoteWidget( 358 child: BlockQuoteWidget(
348 color: Theme.of(context).colorScheme.onSurfaceVariant, 359 color: Theme.of(context).colorScheme.onSurfaceVariant,
349 direction: config.textDirection, 360 direction: config.textDirection,
  361 + width: 3,
350 child: Padding( 362 child: Padding(
351 - padding: const EdgeInsetsDirectional.only(start: 10.0), 363 + padding: const EdgeInsetsDirectional.only(start: 8.0),
352 child: config.getRich(child), 364 child: config.getRich(child),
353 ), 365 ),
354 ), 366 ),
@@ -873,7 +885,7 @@ class ImageMd extends InlineMd { @@ -873,7 +885,7 @@ class ImageMd extends InlineMd {
873 class TableMd extends BlockMd { 885 class TableMd extends BlockMd {
874 @override 886 @override
875 String get expString => 887 String get expString =>
876 - (r"(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?))(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?)))+)$"); 888 + (r"(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?)\ *)(\n\ *(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?))\ *)+)$");
877 @override 889 @override
878 Widget build( 890 Widget build(
879 BuildContext context, 891 BuildContext context,
@@ -886,6 +898,7 @@ class TableMd extends BlockMd { @@ -886,6 +898,7 @@ class TableMd extends BlockMd {
886 .map<Map<int, String>>( 898 .map<Map<int, String>>(
887 (e) => 899 (e) =>
888 e 900 e
  901 + .trim()
889 .split('|') 902 .split('|')
890 .where((element) => element.isNotEmpty) 903 .where((element) => element.isNotEmpty)
891 .toList() 904 .toList()
@@ -939,7 +952,7 @@ class TableMd extends BlockMd { @@ -939,7 +952,7 @@ class TableMd extends BlockMd {
939 children: List.generate(maxCol, (index) { 952 children: List.generate(maxCol, (index) {
940 var e = entry.value; 953 var e = entry.value;
941 String data = e[index] ?? ""; 954 String data = e[index] ?? "";
942 - if (RegExp(r"^--+$").hasMatch(data.trim()) || 955 + if (RegExp(r"^:?--+:?$").hasMatch(data.trim()) ||
943 data.trim().isEmpty) { 956 data.trim().isEmpty) {
944 return const SizedBox(); 957 return const SizedBox();
945 } 958 }