saminsohag

some fixes for italic and bold text

... ... @@ -11,7 +11,7 @@ import 'md_widget.dart';
/// Markdown components
abstract class MarkdownComponent {
static final List<MarkdownComponent> components = [
static List<MarkdownComponent> get components => [
CodeBlockMd(),
NewLines(),
TableMd(),
... ... @@ -25,9 +25,9 @@ abstract class MarkdownComponent {
ImageMd(),
HighlightedText(),
BoldMd(),
ItalicMd(),
LatexMathMultyLine(),
LatexMath(),
ItalicMd(),
ATagMd(),
SourceTag(),
];
... ... @@ -435,7 +435,7 @@ class HighlightedText extends InlineMd {
/// Bold text component
class BoldMd extends InlineMd {
@override
RegExp get exp => RegExp(r"\*\*(([\S^\*].*?)?[\S^\*?])\*\*");
RegExp get exp => RegExp(r"(?<!\*)\*\*(?<!\s)(.+?)(?<!\s)\*\*(?!\*)");
@override
InlineSpan span(
... ... @@ -458,6 +458,32 @@ class BoldMd extends InlineMd {
}
}
/// Italic text component
class ItalicMd extends InlineMd {
@override
RegExp get exp => RegExp(r"(?<!\*)\*(?<!\s)(.+?)(?<!\s)\*(?!\*)", dotAll: true);
@override
InlineSpan span(
BuildContext context,
String text,
final GptMarkdownConfig config,
) {
var match = exp.firstMatch(text.trim());
var conf = config.copyWith(
style: (config.style ?? const TextStyle())
.copyWith(fontStyle: FontStyle.italic));
return TextSpan(
children: MarkdownComponent.generate(
context,
"${match?[1]}",
conf,
),
style: conf.style,
);
}
}
class LatexMathMultyLine extends BlockMd {
@override
RegExp get exp => RegExp(
... ... @@ -589,32 +615,6 @@ class LatexMath extends InlineMd {
}
}
/// Italic text component
class ItalicMd extends InlineMd {
@override
RegExp get exp => RegExp(r"\*(\S(.*?\S)?)\*", dotAll: true);
@override
InlineSpan span(
BuildContext context,
String text,
final GptMarkdownConfig config,
) {
var match = exp.firstMatch(text.trim());
var conf = config.copyWith(
style: (config.style ?? const TextStyle())
.copyWith(fontStyle: FontStyle.italic));
return TextSpan(
children: MarkdownComponent.generate(
context,
"${match?[1]}",
conf,
),
style: conf.style,
);
}
}
/// source text component
class SourceTag extends InlineMd {
@override
... ...