generate static method
Generate widget for markdown widget
Implementation
static List<InlineSpan> generate(
BuildContext context,
String text,
final GptMarkdownConfig config,
) {
List<InlineSpan> spans = [];
List<String> regexes =
components.map<String>((e) => e.exp.pattern).toList();
final combinedRegex = RegExp(
regexes.join("|"),
multiLine: true,
dotAll: true,
);
text.splitMapJoin(
combinedRegex,
onMatch: (p0) {
String element = p0[0] ?? "";
for (var each in components) {
if (each.exp.hasMatch(element)) {
if (each.inline) {
spans.add(each.span(context, element, config));
} else {
spans.addAll([
TextSpan(
text: "\n ",
style: TextStyle(
fontSize: 0,
height: 0,
color: config.style?.color,
),
),
each.span(context, element, config),
TextSpan(
text: "\n ",
style: TextStyle(
fontSize: 0,
height: 0,
color: config.style?.color,
),
),
]);
}
return "";
}
}
return "";
},
onNonMatch: (p0) {
spans.add(TextSpan(text: p0, style: config.style));
return "";
},
);
return spans;
}