onMatch method
Processes match
, adding nodes to parser
and possibly advancing
parser
.
Returns whether the caller should advance parser
by match[0].length
.
Implementation
@override
bool onMatch(InlineParser parser, Match match) {
int consumeLength;
final isEmailLink = match[2] != null;
if (isEmailLink) {
consumeLength = match.match.length;
} else {
consumeLength = _getConsumeLength(match.match);
}
var text = match.match.substring(0, consumeLength);
text = parser.encodeHtml ? escapeHtml(text) : text;
var destination = text;
if (isEmailLink) {
destination = 'mailto:$destination';
} else if (destination[0] == 'w') {
// When there is no scheme specified, insert the scheme `http`.
destination = 'http://$destination';
}
final anchor = Element.text('a', text)
..attributes['href'] = Uri.encodeFull(destination);
parser
..addNode(anchor)
..consume(consumeLength);
return true;
}