{% macro excerptWithHighlight(index, unsafe_excerpt, q) %}
  {% set modified_excerpt = unsafe_excerpt %}
  {% if index > 0 %}
    {% set modified_excerpt = '...' ~ modified_excerpt %}
  {% endif %}
  {% set modified_excerpt = modified_excerpt ~ '...' %}
  {% set text = modified_excerpt|hl(q) %}
  <div class="files-list-item-text-excerpt">{{ text|raw }}</div>
{% endmacro %}

{% import _self as macros %}

{% set subtitle = file.getSubtitle() %}
{% set meta = file.getMeta(search_query) %}
{% set title = file.getTitleHtml() %}
{% if not title %}
  {% set title = file.getTitle()|hl(search_query) %}
{% endif %}

<a href="{{ file.getUrl() }}"
   class="files-list-item clearfix"
   data-id="{{ file.getId() }}"
   {% if file.isTargetBlank() %}target="_blank"{% endif %}
>
  <div class="files-list-item-icon">{{ svg(file.getIcon()~'_20') }}</div>
  <div class="files-list-item-info">
    <div class="files-list-item-title">
      <span class="files-list-item-title-label">{{ title|raw }}</span>

      {% if file.type == 'folder' and file.isTargetBlank() %}
        <span class="files-list-item-title-label-external-icon">{{ svg('arrow_up_right_out_square_outline_12') }}</span>
      {% endif %}

      {% if subtitle %}
        <span class="files-list-item-subtitle">{{ subtitle }}</span>
      {% endif %}

      {% if meta.inline %}
        {%- for item in meta.items -%}
          <div class="files-list-item-meta-item">{{ item|raw }}</div>
        {%- endfor -%}
      {% endif %}
    </div>

    {% if meta.items and not meta.inline %}
      <div class="files-list-item-meta">
        {%- for item in meta.items -%}
          <div class="files-list-item-meta-item">{{ item|raw }}</div>
        {%- endfor -%}
      </div>
    {% endif %}

    {% if text_excerpts[file.getId()] %}
      {{ macros.excerptWithHighlight(text_excerpts[file.getId()]['index'], text_excerpts[file.getId()]['excerpt'], search_query) }}
    {% endif %}
  </div>
</a>