span method

  1. @override
InlineSpan span(
  1. BuildContext context,
  2. String text,
  3. GptMarkdownConfig config
)
override

Implementation

@override
InlineSpan span(
  BuildContext context,
  String text,
  final GptMarkdownConfig config,
) {
  var match = exp.firstMatch(text.trim());
  var highlightedText = match?[1] ?? "";

  if (config.highlightBuilder != null) {
    return WidgetSpan(
      alignment: PlaceholderAlignment.middle,
      child: config.highlightBuilder!(
        context,
        highlightedText,
        config.style ?? const TextStyle(),
      ),
    );
  }

  var style =
      config.style?.copyWith(
        fontWeight: FontWeight.bold,
        background:
            Paint()
              ..color = GptMarkdownTheme.of(context).highlightColor
              ..strokeCap = StrokeCap.round
              ..strokeJoin = StrokeJoin.round,
      ) ??
      TextStyle(
        fontWeight: FontWeight.bold,
        background:
            Paint()
              ..color = GptMarkdownTheme.of(context).highlightColor
              ..strokeCap = StrokeCap.round
              ..strokeJoin = StrokeJoin.round,
      );

  return TextSpan(text: highlightedText, style: style);
}