{% extends "base.html" %}
{% block title %}{{ capsule.title or user.username + "'s capsule" }}{% endblock %}
{% block content %}
<div class="bbs-header">
    <h1>{{ capsule.title or user.username + "'s capsule" }}</h1>
    <p class="text-muted">by {{ user.username }} — last updated
        {{ capsule.updated_at.strftime('%Y-%m-%d') }}
        — <a href="{{ url_for('gemini.raw_gemtext', username=user.username) }}">raw .gmi</a></p>
</div>
<div class="card">
    <div class="card-body" style="font-family:monospace;line-height:1.5;">
{# Render gemtext as HTML — minimal: links, headings, lists, quotes, pre #}
{% set in_pre = namespace(open=False) %}
{% for line in (capsule.content or '').splitlines() %}
    {% if line.startswith('```') %}
        {% if in_pre.open %}</pre>{% set in_pre.open = False %}
        {% else %}<pre style="background:#000;color:#0f0;padding:6px;">{% set in_pre.open = True %}{% endif %}
    {% elif in_pre.open %}{{ line }}
    {% elif line.startswith('=> ') %}
        {% set parts = line[3:].split(None, 1) %}
        <div>→ <a href="{{ parts[0] }}">{{ parts[1] if parts|length > 1 else parts[0] }}</a></div>
    {% elif line.startswith('### ') %}<h3>{{ line[4:] }}</h3>
    {% elif line.startswith('## ') %}<h2>{{ line[3:] }}</h2>
    {% elif line.startswith('# ') %}<h1>{{ line[2:] }}</h1>
    {% elif line.startswith('* ') %}<div>• {{ line[2:] }}</div>
    {% elif line.startswith('> ') %}<blockquote class="text-muted">{{ line[2:] }}</blockquote>
    {% elif line.strip() == '' %}<br>
    {% else %}<div>{{ line }}</div>
    {% endif %}
{% endfor %}
{% if in_pre.open %}</pre>{% endif %}
    </div>
</div>
<div class="mt-3">
    <a href="{{ url_for('gemini.index') }}" class="btn btn-link">← All capsules</a>
</div>
{% endblock %}
