{# The whole manual on one page: the chapters listed in front matter, in order. Each chapter's ids get the chapter as a prefix, #markdown-tables, so they stay unique; links between chapters become links on this page; the chapter's headings move one level down, under the chapter title. #} {% extends "base.html" %} {% block code_css %}{% endblock %} {% block main %} {% set all = namespace(chapters=[]) %} {% for c in page.chapters %}{% set all.chapters = all.chapters + pages("/" ~ c) %}{% endfor %}

{{ page.title }}

{{ page.content }} {% for p in all.chapters %} {% set c = page.chapters[loop.index0] %} {% set ns = namespace(h=p.content) %} {# replace escapes plain text it puts into HTML: mark the new text safe #} {% set ns.h = ns.h | replace('id="', ('id="' ~ c ~ '-') | safe) | replace('href="#', ('href="#' ~ c ~ '-') | safe) %} {% set ns.h = ns.h | replace('href="#' ~ c ~ '-"', 'href="#"' | safe) %} {# Links to other chapters #} {% for o in page.chapters %} {% set ns.h = ns.h | replace('href="/' ~ o ~ '/#', ('href="#' ~ o ~ '-') | safe) | replace('href="/' ~ o ~ '/"', ('href="#' ~ o ~ '"') | safe) %} {% endfor %} {# Headings one level down #} {% for n in [4, 3, 2] %} {% set ns.h = ns.h | replace('', ('') | safe) %} {% endfor %}

{{ loop.index }}. {{ p.title }}

{{ ns.h }}
{% endfor %}
{% endblock %}