tex_markdown.dart
1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library tex_markdown;
import 'package:flutter/material.dart';
import 'md_widget.dart';
/// This widget create a full markdown widget as a column view.
class TexMarkdown extends StatelessWidget {
const TexMarkdown(
this.data, {
super.key,
this.style,
this.followLinkColor = false,
this.textDirection = TextDirection.ltr,
this.onLinkTab,
});
final TextDirection textDirection;
final String data;
final TextStyle? style;
final void Function(String url, String title)? onLinkTab;
final bool followLinkColor;
static String toHtml(String text) {
String html = "";
text.trim().split(RegExp(r"\n\n+")).forEach((element) {
html += '<p>${MdWidget.toHtml(element)}</p>';
});
return html;
}
@override
Widget build(BuildContext context) {
return ClipRRect(
child: MdWidget(
data.trim(),
textDirection: textDirection,
style: style,
onLinkTab: onLinkTab,
followLinkColor: followLinkColor,
));
}
}