<commit_before>{% comment %}
Copyright (C) 2017-2020  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% load swh_templatetags %}

{% include "includes/revision-info.html" %}

{% if snapshot_context and snapshot_context.is_empty %}
  {% include "includes/empty-snapshot.html" %}
{% else %}
  <div class="card">
    {% if filename %}
      <div class="swh-content-filename card-header bg-gray-light swh-heading-color">
        {{ filename }}
      </div>
    {% endif %}
    <div class="swh-content">
      {% if content_size > max_content_size %}
        Content is too large to be displayed (size is greater than {{ max_content_size|filesizeformat }}).
      {% elif "inode/x-empty" == mimetype %}
        <i>File is empty</i>
      {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
        <div class="swh-ipynb">
        </div>
      {% elif "text/" in mimetype or "application/" in mimetype and encoding != "binary" %}
        <div class="highlightjs">
          <pre><code class="{{ language }}">{{ content }}</code></pre>
        </div>
      {% elif mimetype in browsers_supported_image_mimes and content %}
        <img src="data:{{ mimetype }};base64,{{ content }}"/>
      {% elif "application/pdf" == mimetype %}
        <div class="text-center">
          <div class="py-2">
            <button class="btn btn-default btn-sm" id="pdf-prev">Previous</button>
            <span>Page: <span id="pdf-page-num"></span> / <span id="pdf-page-count"></span></span>
            <button class="btn btn-default btn-sm" id="pdf-next">Next</button>
          </div>
          <canvas id="pdf-canvas"></canvas>
        </div>
      {% elif content %}
        Content with mime type {{ mimetype }} and encoding {{ encoding }} cannot be displayed.
      {% else %}
        {% include "includes/http-error.html" %}
      {% endif %}
    </div>
  </div>

  <script>
    {% if "application/pdf" == mimetype %}
      swh.webapp.renderPdf({{ top_right_link.url|jsonify }});
    {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
      swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb');
    {% elif content %}
      let codeContainer = $('code');
      let content = codeContainer.text();

      swh.webapp.highlightCode();

      function updateLanguage(language) {
        codeContainer.text(content);
        codeContainer.removeClass();
        codeContainer.addClass(language);

        let urlParams = new URLSearchParams(window.location.search);
        urlParams.set('language', language);

        const newUrl = window.location.pathname + '?' + urlParams.toString() + window.location.hash;
        window.history.replaceState('', document.title, newUrl);

        swh.webapp.highlightCode();
      }

    {% endif %}
  </script>
{% endif %}<commit_msg>templates/content-display: Remove script tag when no content to display<commit_after>{% comment %}
Copyright (C) 2017-2020  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% load swh_templatetags %}

{% include "includes/revision-info.html" %}

{% if snapshot_context and snapshot_context.is_empty %}
  {% include "includes/empty-snapshot.html" %}
{% else %}
  <div class="card">
    {% if filename %}
      <div class="swh-content-filename card-header bg-gray-light swh-heading-color">
        {{ filename }}
      </div>
    {% endif %}
    <div class="swh-content">
      {% if content_size > max_content_size %}
        Content is too large to be displayed (size is greater than {{ max_content_size|filesizeformat }}).
      {% elif "inode/x-empty" == mimetype %}
        <i>File is empty</i>
      {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
        <div class="swh-ipynb">
        </div>
      {% elif "text/" in mimetype or "application/" in mimetype and encoding != "binary" %}
        <div class="highlightjs">
          <pre><code class="{{ language }}">{{ content }}</code></pre>
        </div>
      {% elif mimetype in browsers_supported_image_mimes and content %}
        <img src="data:{{ mimetype }};base64,{{ content }}"/>
      {% elif "application/pdf" == mimetype %}
        <div class="text-center">
          <div class="py-2">
            <button class="btn btn-default btn-sm" id="pdf-prev">Previous</button>
            <span>Page: <span id="pdf-page-num"></span> / <span id="pdf-page-count"></span></span>
            <button class="btn btn-default btn-sm" id="pdf-next">Next</button>
          </div>
          <canvas id="pdf-canvas"></canvas>
        </div>
      {% elif content %}
        Content with mime type {{ mimetype }} and encoding {{ encoding }} cannot be displayed.
      {% else %}
        {% include "includes/http-error.html" %}
      {% endif %}
    </div>
  </div>

  {% if content %}
    <script>
      {% if "application/pdf" == mimetype %}
        swh.webapp.renderPdf({{ top_right_link.url|jsonify }});
      {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
        swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb');
      {% elif content %}
        let codeContainer = $('code');
        let content = codeContainer.text();

        swh.webapp.highlightCode();

        function updateLanguage(language) {
          codeContainer.text(content);
          codeContainer.removeClass();
          codeContainer.addClass(language);

          let urlParams = new URLSearchParams(window.location.search);
          urlParams.set('language', language);

          const newUrl = window.location.pathname + '?' + urlParams.toString() + window.location.hash;
          window.history.replaceState('', document.title, newUrl);

          swh.webapp.highlightCode();
        }

      {% endif %}
    </script>
  {% endif %}
{% endif %}
{'fraction_non_alphanumeric': 0.15811757042826902, 'fraction_numerical': 0.004559517993812083, 'mean_word_length': 2.7866831072749694, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4619281', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1762, 'n_words': 443}