format method

  1. @override
TextSpan format(
  1. String src
)
override

Implementation

@override
TextSpan format(String src) {
  _src = src;
  _scanner = StringScanner(_src);

  if (_generateSpans()) {
    // Successfully parsed the code
    final List<TextSpan> formattedText = <TextSpan>[];
    int currentPosition = 0;

    for (_HighlightSpan span in _spans) {
      if (currentPosition != span.start)
        formattedText
            .add(TextSpan(text: _src.substring(currentPosition, span.start)));

      formattedText.add(TextSpan(
          style: span.textStyle(_style), text: span.textForSpan(_src)));

      currentPosition = span.end;
    }

    if (currentPosition != _src.length)
      formattedText
          .add(TextSpan(text: _src.substring(currentPosition, _src.length)));

    return TextSpan(style: _style!.baseStyle, children: formattedText);
  } else {
    // Parsing failed, return with only basic formatting
    return TextSpan(style: _style!.baseStyle, text: src);
  }
}