<!DOCTYPE html>
<html lang="{{ (grav.language.getActive ?: grav.config.site.default_lang)|e }}">
<head>
{% block head %}
    <meta charset="utf-8" />
    <title>{% if header.title %}{{ header.title|e }} | {% endif %}{{ site.title|e }}</title>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {% include 'partials/metadata.html.twig' %}

    <link rel="icon" type="image/png" href="{{ url('theme://images/logo.png')|e }}" />
    <link rel="canonical" href="{{ page.canonical(true)|e }}" />
    <script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>
{% endblock head %}

{% block stylesheets %}
    {% do assets.addCss('https://unpkg.com/purecss@1.0.0/build/pure-min.css', 100) %}
    {% do assets.addCss('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', 99) %}
    {% do assets.addCss('theme://css/pagedjs.css', 98) %}
    {% do assets.addCss('theme://css/custom.css', 97) %}
    {% do assets.addCss('theme://fonts/fonts.css', 96) %}
    {% do assets.addCss('theme://css/mep_carnet.css', 95) %}
{% endblock %}

{% block javascripts %}
    {% do assets.addJs('jquery', 100) %}
{% endblock %}

{% block assets deferred %}
    {{ assets.css()|raw }}
    {{ assets.js()|raw }}
{% endblock %}
</head>
<body id="top" class="{{ page.header.body_classes|e }}">

        {% block body %}
            <section id="body">
                <div>
                {% block content %}{% endblock %}
                </div>
            </section>
        {% endblock %}


{% block bottom %}
    {{ assets.js('bottom')|raw }}
{% endblock %}
<script>
    // transformer les balises [...] en <div class="...">
	let content = document.getElementById('body');

        content = content.innerHTML.replaceAll(/\[([^\/\]]+)\]/g, '<div class="$1">');
        content = content.replaceAll(/\[\/([^\]]+)\]/g, '</div>');

        document.getElementById("body").innerHTML = content;
    
    // isoler les chiffres des titres
    let moments = document.getElementsByClassName("moment");

    for(let i = 0; i < moments.length; i++) {
        moments[i].innerHTML = "<span class='first-letter'>" + moments[i].innerHTML.substring(0, moments[i].innerHTML.indexOf('—')) + "</span>" + moments[i].innerHTML.slice(moments[i].innerHTML.indexOf(' —'));
    }

    // cleaner le balisage des éléments contenant plusieurs paragraphes
    let labeurs = document.getElementsByClassName("labeur");
    for(let i = 0; i < labeurs.length; i++) {
        if (labeurs[i].childNodes.length == 1) {
            labeurs[i].innerHTML = '<p>' + labeurs[i].innerHTML + '</p>';
        } else {
            labeurs[i].innerHTML = "<p>" + labeurs[i].innerHTML.replace("<p>", "");
        }
        for(j = 0; j < labeurs[i].childNodes.length; j++) {
            if (labeurs[i].childNodes[j].innerHTML != undefined) {
                labeurs[i].childNodes[j].innerHTML = labeurs[i].childNodes[j].innerHTML.replaceAll(' :', '&nbsp;:');
            }
        }
    }   

</script>
</body>
</html>
