String processTipInstruction()

in tool/create_code_with_tooltips.dart [116:147]


  String processTipInstruction(
      List<String> tooltipAnchors, int lineNum, String line /*src line*/) {
    _log.fine(line);
    line = htmlEscape(line);

    for (var anchorText in tooltipAnchors) {
      final escapedAnchorText = htmlEscape(anchorText);
      if (!line.contains(escapedAnchorText)) {
        throw "Error: $srcPath:$lineNum doesn't contain "
            "the tip anchor text '$anchorText': '$line'";
      }

      final tooltip = tooltips[indexOfNextTooltip];
      final tooltipAnchor = tooltip[0];
      final tooltipTitle = tooltip[1];
      final tooltipText = tooltip[2];

      indexOfNextTooltip++;
      if (tooltipAnchor != anchorText) {
        throw "Error in tooltip data entry order: "
            "expected tip for '$anchorText', but instead found tip for '$tooltipAnchor'. Aborting.";
      }

      _log.fine('  ** Replacing "$escapedAnchorText" with tooltip');
      final anchorWithTip =
          '<a tabindex="0" role="button" data-toggle="popover"' +
              (tooltipTitle.isEmpty ? '' : ' title="$tooltipTitle"') +
              ' data-content="$tooltipText">$escapedAnchorText</a>';
      line = line.replaceFirst(escapedAnchorText, anchorWithTip);
    }
    return line;
  }