onMatch method

  1. @override
bool onMatch(
  1. InlineParser parser,
  2. Match match
)

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) {
  var title = match.group(1);
  final fileName = match.group(2);

  if (title != null && title.isEmpty) {
    title = null;
  }

  if (fileName == null) {
    return false;
  }

  final sidebarEntry = findEntry(_getInternalUrl(fileName));
  if (sidebarEntry != null) {
    final finalTitle = title ?? sidebarEntry["name"];

    parser.addNode(Text("<a href='$fileName.html'>$finalTitle</a>"));
    return true;
  }

  if (title != null) {
    parser.addNode(Text("<a href='$fileName.html'>$title</a>"));
    return true;
  }

  return false;
}