visitText method

  1. @override
void visitText(
  1. Text text
)

Called when a Text node has been reached.

Implementation

@override
void visitText(md.Text text) {
  debugPrint('text ${text.text}');

  if (_elementList.isEmpty) return;
  var last = _elementList.last;
  last.textSpans ??= [];

  // 替换特定字符串
  var content = text.text.replaceAll('>', '>');
  content = content.replaceAll('&lt;', '<');

  if (last.tag == 'a') {
    last.textSpans?.add(TextSpan(
      text: content,
      style: last.textStyle,
      recognizer: TapGestureRecognizer()
        ..onTap = () {
          debugPrint(last.attributes.toString());
          linkTap(last.attributes['href'] ?? '');
        },
    ));
    return;
  }

  last.textSpans?.add(TextSpan(
    text: content,
    style: last.textStyle,
  ));
}