{#- chirp-ui: Citations citation_chip: inline numbered linking to a source (text-fragment aware). sources_summary: compact stacked source pills (reuses avatar_stack overflow CSS). citation_modal: full source detail over modal.html. Usage: {% from "chirpui/citations.html" import citation_chip, sources_summary, citation_modal %} {{ citation_chip(index=1, title="Scope spec", href="https://x.test/doc", source_id="src-1") }} {{ sources_summary(sources=[{"id": "src-1", "title": "Scope spec", "href": "https://x.test/doc", "relevance": "high"}]) }} -#} {% from "chirpui/modal.html" import modal %} {% def citation_chip(index, title, href, source_id="", chunk=none, cls="") %} {% set _href = build_text_fragment_url(href, chunk) if chunk else href %} {{ index }} {% end %} {% def sources_summary(sources, max_visible=4, label="Sources", cls="") %} {% set _total = sources | length %}
{% for s in sources %} {% if loop.index <= max_visible %} {{ loop.index }} {% end %} {% end %} {% if _total > max_visible %} +{{ _total - max_visible }} {% end %}
{% end %} {% def citation_modal(source, cls="") %} {% set _id = "citation-" ~ (source.get("id") | default("src")) %} {% call modal(_id, title=source.get("title") | default("Source"), size="md", cls=cls) %}
{% if source.get("href") %}

{{ source.href }}

{% end %} {% if source.get("excerpt") %}
{{ source.excerpt }}
{% end %}
{% end %} {% end %}