md_widget.dart
1.33 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
part of 'gpt_markdown.dart';
/// It creates a markdown widget closed to each other.
class MdWidget extends StatelessWidget {
const MdWidget(this.exp, {super.key, required this.config});
final String exp;
final GptMarkdownConfig config;
@override
Widget build(BuildContext context) {
List<InlineSpan> list = [];
list.addAll(
MarkdownComponent.generate(
context,
exp,
// .replaceAllMapped(
// RegExp(
// r"\\\[(.*?)\\\]|(\\begin.*?\\end{.*?})",
// multiLine: true,
// dotAll: true,
// ), (match) {
// //
// String body = (match[1] ?? match[2])?.replaceAll("\n", " ") ?? "";
// return "\\[$body\\]";
// }),
config,
),
);
return config.getRich(
TextSpan(children: list, style: config.style?.copyWith()),
);
}
}
class CustomTableColumnWidth extends TableColumnWidth {
@override
double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) {
double width = 50;
for (var each in cells) {
each.layout(const BoxConstraints(), parentUsesSize: true);
width = max(width, each.size.width);
}
return min(containerWidth, width);
}
@override
double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) {
return 50;
}
}