saminsohag

some fixes for italic and bold text

@@ -11,7 +11,7 @@ import 'md_widget.dart'; @@ -11,7 +11,7 @@ import 'md_widget.dart';
11 11
12 /// Markdown components 12 /// Markdown components
13 abstract class MarkdownComponent { 13 abstract class MarkdownComponent {
14 - static final List<MarkdownComponent> components = [ 14 + static List<MarkdownComponent> get components => [
15 CodeBlockMd(), 15 CodeBlockMd(),
16 NewLines(), 16 NewLines(),
17 TableMd(), 17 TableMd(),
@@ -25,9 +25,9 @@ abstract class MarkdownComponent { @@ -25,9 +25,9 @@ abstract class MarkdownComponent {
25 ImageMd(), 25 ImageMd(),
26 HighlightedText(), 26 HighlightedText(),
27 BoldMd(), 27 BoldMd(),
  28 + ItalicMd(),
28 LatexMathMultyLine(), 29 LatexMathMultyLine(),
29 LatexMath(), 30 LatexMath(),
30 - ItalicMd(),  
31 ATagMd(), 31 ATagMd(),
32 SourceTag(), 32 SourceTag(),
33 ]; 33 ];
@@ -435,7 +435,7 @@ class HighlightedText extends InlineMd { @@ -435,7 +435,7 @@ class HighlightedText extends InlineMd {
435 /// Bold text component 435 /// Bold text component
436 class BoldMd extends InlineMd { 436 class BoldMd extends InlineMd {
437 @override 437 @override
438 - RegExp get exp => RegExp(r"\*\*(([\S^\*].*?)?[\S^\*?])\*\*"); 438 + RegExp get exp => RegExp(r"(?<!\*)\*\*(?<!\s)(.+?)(?<!\s)\*\*(?!\*)");
439 439
440 @override 440 @override
441 InlineSpan span( 441 InlineSpan span(
@@ -458,6 +458,32 @@ class BoldMd extends InlineMd { @@ -458,6 +458,32 @@ class BoldMd extends InlineMd {
458 } 458 }
459 } 459 }
460 460
  461 +/// Italic text component
  462 +class ItalicMd extends InlineMd {
  463 + @override
  464 + RegExp get exp => RegExp(r"(?<!\*)\*(?<!\s)(.+?)(?<!\s)\*(?!\*)", dotAll: true);
  465 +
  466 + @override
  467 + InlineSpan span(
  468 + BuildContext context,
  469 + String text,
  470 + final GptMarkdownConfig config,
  471 + ) {
  472 + var match = exp.firstMatch(text.trim());
  473 + var conf = config.copyWith(
  474 + style: (config.style ?? const TextStyle())
  475 + .copyWith(fontStyle: FontStyle.italic));
  476 + return TextSpan(
  477 + children: MarkdownComponent.generate(
  478 + context,
  479 + "${match?[1]}",
  480 + conf,
  481 + ),
  482 + style: conf.style,
  483 + );
  484 + }
  485 +}
  486 +
461 class LatexMathMultyLine extends BlockMd { 487 class LatexMathMultyLine extends BlockMd {
462 @override 488 @override
463 RegExp get exp => RegExp( 489 RegExp get exp => RegExp(
@@ -589,32 +615,6 @@ class LatexMath extends InlineMd { @@ -589,32 +615,6 @@ class LatexMath extends InlineMd {
589 } 615 }
590 } 616 }
591 617
592 -/// Italic text component  
593 -class ItalicMd extends InlineMd {  
594 - @override  
595 - RegExp get exp => RegExp(r"\*(\S(.*?\S)?)\*", dotAll: true);  
596 -  
597 - @override  
598 - InlineSpan span(  
599 - BuildContext context,  
600 - String text,  
601 - final GptMarkdownConfig config,  
602 - ) {  
603 - var match = exp.firstMatch(text.trim());  
604 - var conf = config.copyWith(  
605 - style: (config.style ?? const TextStyle())  
606 - .copyWith(fontStyle: FontStyle.italic));  
607 - return TextSpan(  
608 - children: MarkdownComponent.generate(  
609 - context,  
610 - "${match?[1]}",  
611 - conf,  
612 - ),  
613 - style: conf.style,  
614 - );  
615 - }  
616 -}  
617 -  
618 /// source text component 618 /// source text component
619 class SourceTag extends InlineMd { 619 class SourceTag extends InlineMd {
620 @override 620 @override