tex_markdown.dart
1.2 KB
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
42
43
44
45
46
47
48
49
50
51
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.onLinkTab,
});
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 Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: data
.trim()
.split(
RegExp(r"\n\n+"),
)
.map<Widget>(
(e) => Padding(
padding: const EdgeInsets.all(4),
child: MdWidget(
e,
style: style,
followLinkColor: followLinkColor,
onLinkTab: onLinkTab,
),
),
)
.toList(),
);
}
}