 (defn format-sexp [items fmt level]
   (when-let [items (fmt items)]
     [(heading (level-to-h level) fmt [fmt])
-     (toc items [fmt] 3 3)
+     (toc items [fmt] 2)
      (set-marker (layout/translations fmt))
      (case fmt
        (:hörfilm :ludo) (entries-sexp items)

      (set/subset? items (set layout/subgenres))
      (keep items layout/subgenres))))

(defn- toc-entry [items path to-depth indent-depth]
  (let [depth (count path)]
    [:fo:block (-> {:text-align-last "justify" :role "TOCI"}
                   (cond-> (>= depth indent-depth) (assoc :start-indent "1em")))
     [:fo:basic-link {:internal-destination (hash path)}
      (inline {:role "Reference"} (layout/translations (last path)))
      " " [:fo:leader {:leader-pattern "dots" :role "NonStruct"}] " "
      [:fo:page-number-citation {:ref-id (hash path) :role "Reference"}]]
     (when (and (map? items) (< depth to-depth))
       (keep #(toc-entry (% items) (conj path %) to-depth indent-depth) (order (keys items))))]))

(defn toc [items path to-depth indent-depth & {:keys [heading? editorial? recommendation-at-end? single-recommendation?]}]
  (when (map? items)
    [:fo:block {:line-height "150%"
                :role "TOC"}
     (when heading? (heading :h1 :inhalt []))
     (let [entries (order (keys items))
           entries (cond
                     recommendation-at-end? (concat [:editorial] entries [(if single-recommendation?
                                                                            :recommendation
                                                                            :recommendations)])
                     editorial? (concat [:editorial (if single-recommendation?
                                                      :recommendation
                                                      :recommendations)] entries)
                     :else entries)]
       (keep #(toc-entry (get items %) (conj path %) to-depth indent-depth) entries))]))

(defn- to-url
  "Return an url given a `record-id`"


    (let [subitems (get items fmt)]
      [:fo:flow {:flow-name "xsl-region-body"}
       (toc subitems [fmt] 2 :heading? true :editorial? true :recommendation-at-end? true)
       (block {:break-before "odd-page"}) ;; the very first format should start on recto
       (heading :h1 :editorial [fmt :editorial])
       (heading :h1 :hörbuch [fmt :hörbuch])
       (mapcat #(genre-sexp subitems fmt % 2) (order (keys subitems)))
       (heading :h1 :recommendations [fmt :recommendations])])]])

(defmethod document-sexp :all-formats
