saminsohag

bug fixed

@@ -106,14 +106,19 @@ $hello$ @@ -106,14 +106,19 @@ $hello$
106 AnimatedBuilder( 106 AnimatedBuilder(
107 animation: _controller, 107 animation: _controller,
108 builder: (context, _) { 108 builder: (context, _) {
109 - return TexMarkdown(  
110 - _controller.text,  
111 - onLinkTab: (url, title) {  
112 - log(title, name: "title");  
113 - log(url, name: "url");  
114 - },  
115 - style: const TextStyle(  
116 - color: Colors.green, 109 + return Material(
  110 + shape: const RoundedRectangleBorder(
  111 + side: BorderSide(width: 1),
  112 + ),
  113 + child: TexMarkdown(
  114 + _controller.text,
  115 + onLinkTab: (url, title) {
  116 + log(title, name: "title");
  117 + log(url, name: "url");
  118 + },
  119 + style: const TextStyle(
  120 + color: Colors.green,
  121 + ),
117 ), 122 ),
118 ); 123 );
119 }), 124 }),
@@ -44,40 +44,28 @@ abstract class MarkdownComponent { @@ -44,40 +44,28 @@ abstract class MarkdownComponent {
44 TextStyle? style, 44 TextStyle? style,
45 final void Function(String url, String title)? onLinkTab, 45 final void Function(String url, String title)? onLinkTab,
46 ) { 46 ) {
47 - List<Widget> children = [];  
48 List<InlineSpan> spans = []; 47 List<InlineSpan> spans = [];
49 text.split(RegExp(r"\n+")).forEach( 48 text.split(RegExp(r"\n+")).forEach(
50 (element) { 49 (element) {
51 for (var each in components) { 50 for (var each in components) {
52 if (each.exp.hasMatch(element.trim())) { 51 if (each.exp.hasMatch(element.trim())) {
53 if (each is InlineMd) { 52 if (each is InlineMd) {
54 - if (spans.isNotEmpty) {  
55 - spans.add(  
56 - TextSpan(  
57 - text: " ",  
58 - style: style,  
59 - ),  
60 - );  
61 - }  
62 - spans.add(each.inlineSpan( 53 + spans.add(each.span(
63 context, 54 context,
64 element, 55 element,
65 style, 56 style,
66 onLinkTab, 57 onLinkTab,
67 )); 58 ));
  59 + spans.add(
  60 + TextSpan(
  61 + text: " ",
  62 + style: style,
  63 + ),
  64 + );
68 } else { 65 } else {
69 - if (spans.isNotEmpty) {  
70 - children.add(  
71 - Text.rich(  
72 - TextSpan(children: List.from(spans)),  
73 - textAlign: TextAlign.left,  
74 - ),  
75 - );  
76 - spans.clear();  
77 - }  
78 if (each is BlockMd) { 66 if (each is BlockMd) {
79 - children.add(  
80 - each.build(context, element, style, onLinkTab), 67 + spans.add(
  68 + each.span(context, element, style, onLinkTab),
81 ); 69 );
82 } 70 }
83 } 71 }
@@ -86,22 +74,21 @@ abstract class MarkdownComponent { @@ -86,22 +74,21 @@ abstract class MarkdownComponent {
86 } 74 }
87 }, 75 },
88 ); 76 );
89 - if (spans.isNotEmpty) {  
90 - children.add(  
91 - Text.rich(  
92 - TextSpan(  
93 - children: List.from(spans),  
94 - ),  
95 - textAlign: TextAlign.left,  
96 - ),  
97 - );  
98 - }  
99 - return Column(  
100 - crossAxisAlignment: CrossAxisAlignment.start,  
101 - children: children, 77 + return Text.rich(
  78 + TextSpan(
  79 + children: List.from(spans),
  80 + ),
  81 + textAlign: TextAlign.left,
102 ); 82 );
103 } 83 }
104 84
  85 + InlineSpan span(
  86 + BuildContext context,
  87 + String text,
  88 + TextStyle? style,
  89 + final void Function(String url, String title)? onLinkTab,
  90 + );
  91 +
105 RegExp get exp; 92 RegExp get exp;
106 bool get inline; 93 bool get inline;
107 } 94 }
@@ -110,7 +97,9 @@ abstract class MarkdownComponent { @@ -110,7 +97,9 @@ abstract class MarkdownComponent {
110 abstract class InlineMd extends MarkdownComponent { 97 abstract class InlineMd extends MarkdownComponent {
111 @override 98 @override
112 bool get inline => true; 99 bool get inline => true;
113 - InlineSpan inlineSpan( 100 +
  101 + @override
  102 + InlineSpan span(
114 BuildContext context, 103 BuildContext context,
115 String text, 104 String text,
116 TextStyle? style, 105 TextStyle? style,
@@ -123,6 +112,21 @@ abstract class InlineMd extends MarkdownComponent { @@ -123,6 +112,21 @@ abstract class InlineMd extends MarkdownComponent {
123 abstract class BlockMd extends MarkdownComponent { 112 abstract class BlockMd extends MarkdownComponent {
124 @override 113 @override
125 bool get inline => false; 114 bool get inline => false;
  115 + @override
  116 + InlineSpan span(
  117 + BuildContext context,
  118 + String text,
  119 + TextStyle? style,
  120 + final void Function(String url, String title)? onLinkTab,
  121 + ) {
  122 + return WidgetSpan(
  123 + child: Align(
  124 + alignment: Alignment.centerLeft,
  125 + child: build(context, text, style, onLinkTab),
  126 + ),
  127 + );
  128 + }
  129 +
126 Widget build( 130 Widget build(
127 BuildContext context, 131 BuildContext context,
128 String text, 132 String text,
@@ -409,7 +413,7 @@ class BoldMd extends InlineMd { @@ -409,7 +413,7 @@ class BoldMd extends InlineMd {
409 final RegExp exp = RegExp(r"^\*{2}(([\S^\*].*)?[\S^\*])\*{2}$"); 413 final RegExp exp = RegExp(r"^\*{2}(([\S^\*].*)?[\S^\*])\*{2}$");
410 414
411 @override 415 @override
412 - InlineSpan inlineSpan( 416 + InlineSpan span(
413 BuildContext context, 417 BuildContext context,
414 String text, 418 String text,
415 TextStyle? style, 419 TextStyle? style,
@@ -443,7 +447,7 @@ class ItalicMd extends InlineMd { @@ -443,7 +447,7 @@ class ItalicMd extends InlineMd {
443 final RegExp exp = RegExp(r"^\*{1}(([\S^\*].*)?[\S^\*])\*{1}$"); 447 final RegExp exp = RegExp(r"^\*{1}(([\S^\*].*)?[\S^\*])\*{1}$");
444 448
445 @override 449 @override
446 - InlineSpan inlineSpan( 450 + InlineSpan span(
447 BuildContext context, 451 BuildContext context,
448 String text, 452 String text,
449 TextStyle? style, 453 TextStyle? style,
@@ -475,7 +479,7 @@ class ATagMd extends InlineMd { @@ -475,7 +479,7 @@ class ATagMd extends InlineMd {
475 final RegExp exp = RegExp(r"^\[([^\s\*].*[^\s]?)?\]\(([^\s\*]+)?\)$"); 479 final RegExp exp = RegExp(r"^\[([^\s\*].*[^\s]?)?\]\(([^\s\*]+)?\)$");
476 480
477 @override 481 @override
478 - InlineSpan inlineSpan( 482 + InlineSpan span(
479 BuildContext context, 483 BuildContext context,
480 String text, 484 String text,
481 TextStyle? style, 485 TextStyle? style,
@@ -520,7 +524,7 @@ class ImageMd extends InlineMd { @@ -520,7 +524,7 @@ class ImageMd extends InlineMd {
520 final RegExp exp = RegExp(r"^\!\[([^\s].*[^\s]?)?\]\(([^\s]+)\)$"); 524 final RegExp exp = RegExp(r"^\!\[([^\s].*[^\s]?)?\]\(([^\s]+)\)$");
521 525
522 @override 526 @override
523 - InlineSpan inlineSpan( 527 + InlineSpan span(
524 BuildContext context, 528 BuildContext context,
525 String text, 529 String text,
526 TextStyle? style, 530 TextStyle? style,
@@ -578,7 +582,7 @@ class TextMd extends InlineMd { @@ -578,7 +582,7 @@ class TextMd extends InlineMd {
578 final RegExp exp = RegExp(".*"); 582 final RegExp exp = RegExp(".*");
579 583
580 @override 584 @override
581 - InlineSpan inlineSpan(BuildContext context, String text, TextStyle? style, 585 + InlineSpan span(BuildContext context, String text, TextStyle? style,
582 void Function(String url, String title)? onLinkTab) { 586 void Function(String url, String title)? onLinkTab) {
583 return WidgetSpan( 587 return WidgetSpan(
584 alignment: PlaceholderAlignment.baseline, 588 alignment: PlaceholderAlignment.baseline,
@@ -36,7 +36,7 @@ class TexMarkdown extends StatelessWidget { @@ -36,7 +36,7 @@ class TexMarkdown extends StatelessWidget {
36 ) 36 )
37 .map<Widget>( 37 .map<Widget>(
38 (e) => Padding( 38 (e) => Padding(
39 - padding: const EdgeInsets.all(4), 39 + padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 4),
40 child: MdWidget( 40 child: MdWidget(
41 e, 41 e,
42 style: style, 42 style: style,