<?php
/**
 * Vue : affichage d'un document (/doc/:slug).
 * @var string $docTitle  Titre extrait du doc (pour le <title> navigateur)
 * @var string $docHtml   HTML déjà rendu et assaini par Markdown::toHtml()
 */

$pageTitle = $docTitle;
include WEBROOT_PATH . '/includes/header.php';
?>

<p style="margin:0 0 1rem">
    <a href="/doc" class="nav-link" style="padding-left:0">
        <i class="fa-solid fa-arrow-left"></i> <?= t('doc.back') ?>
    </a>
</p>

<article class="card doc-content">
    <?= $docHtml ?>
</article>

<?php if (str_contains($docHtml, 'class="mermaid"')): ?>
    <?php $cdnMermaid = $settings->get('cdn_mermaid_js', 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js'); ?>
    <?php if ($cdnMermaid): ?>
    <script src="<?= htmlspecialchars($cdnMermaid) ?>"></script>
    <script>
        if (window.mermaid) {
            mermaid.initialize({ startOnLoad: false, securityLevel: 'strict' });
            mermaid.run({ querySelector: '.doc-content .mermaid' });
        }
    </script>
    <?php endif; ?>
<?php endif; ?>

<?php include WEBROOT_PATH . '/includes/footer.php'; ?>
