generate static method

List<InlineSpan> generate(
  1. BuildContext context,
  2. String text,
  3. TextStyle? style,
  4. TextDirection textDirection,
  5. void onLinkTab(
    1. String url,
    2. String title
    )?,
)

Generate widget for markdown widget

Implementation

static List<InlineSpan> generate(
  BuildContext context,
  String text,
  TextStyle? style,
  TextDirection textDirection,
  final void Function(String url, String title)? onLinkTab,
) {
  List<InlineSpan> spans = [];
  text.split(RegExp(r"\n+")).forEach(
    (element) {
      for (var each in components) {
        if (each.exp.hasMatch(element.trim())) {
          if (each is InlineMd) {
            spans.add(each.span(
              context,
              element.trim(),
              style,
              textDirection,
              onLinkTab,
            ));
            spans.add(
              TextSpan(
                text: " ",
                style: style,
              ),
            );
          } else {
            if (each is BlockMd) {
              spans.addAll([
                TextSpan(
                  text: "\n ",
                  style: TextStyle(
                    fontSize: 0,
                    height: 0,
                    color: style?.color,
                  ),
                ),
                each.span(
                  context,
                  element.trim(),
                  style,
                  textDirection,
                  onLinkTab,
                ),
                TextSpan(
                  text: "\n ",
                  style: TextStyle(
                    fontSize: 0,
                    height: 0,
                    color: style?.color,
                  ),
                ),
              ]);
            }
          }
          return;
        }
      }
    },
  );
  return spans;
}