{% macro code_with_search_link(text, query) %}
    <a href="{{ url_for('index', query=text) }}"><code>{{ text | highlight(query) | safe }}</code></a>
{% endmacro %}

{% macro file_diff_link(filename) %}
    <a href="#diff-{{filename}}">file diff</a>
{% endmacro %}

{% macro display_file_list(files, query, diffs) %}
  {% if files | length > 0 %}
    <ul class="list-unstyled">
      {% for item in files %}
        {% set info = [] %}

        {% if not files[0] is string %}
          {% set filename = item[0] %}
          {% do info.append(code_with_search_link(item[1], query)) %}
        {% else %}
          {% set filename = item %}
        {% endif %}

        {% if diffs %}
          {% do info.append(file_diff_link(filename)) %}
        {% endif %}

        <li>{{ code_with_search_link(filename, query) }}
          {% if info | length > 0 %}
            >>>
            {% for inf in info %}
              {{inf}}{% if not loop.last %} <b>&middot;</b> {% endif %}
            {% endfor %}
          {% endif %}
        </li>
      {% endfor %}
    </ul>
  {% else %}
    <em>none</em>
  {% endif %}
{% endmacro %}

{% macro display_file_list_single_line(files, query) %}
  {% if files | length > 0 %}
    {% if files[0] is string %}
      {% for item in files %}
        <span class="glyphicon glyphicon-file"></span> {{ code_with_search_link(item, query) }}{% if not loop.last %} &middot; {% endif %}
      {% endfor %}
    {% else %}
      {% for item in files %}
        <span class="glyphicon glyphicon-file"></span> {{ code_with_search_link(item[0], query) }} (hash code: {{ code_with_search_link(item[1], query)}}){% if not loop.last %} &middot; {% endif %}
      {% endfor %}
    {% endif %}
  {% else %}
    <em>none</em>
  {% endif %}
{% endmacro %}
