package yocaml
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Core engine of the YOCaml Static Site Generator
Install
dune-project
Dependency
Authors
Maintainers
Sources
yocaml-2.0.0.tbz
sha256=fddf61500e828ac88d86ba982084cc817299302082a6e797b36787ff18235ec2
sha512=8b71a8cecd3e101df55eef0bba7a24d4dde9d66b5ecedd9f6d55834fcdc8d33fd875092ca73a398e1715664caee06cdc1bdb1b4da85bff0a687faac5c0445023
doc/src/yocaml/markup.ml.html
Source file markup.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69(* YOCaml a static blog generator. Copyright (C) 2024 The Funkyworkers and The YOCaml's developers This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. *) module Toc = struct type 'a element = { content : 'a; children : 'a t } and 'a t = 'a element list let from_list labels = let rec aux depth acc = function | [] -> (List.rev acc, []) | (level, _) :: _ as labels when level < depth -> (List.rev acc, labels) | (level, content) :: xs when level = depth -> let children, xs = aux (succ depth) [] xs in let entry = { content; children } in let remaining, xs = aux depth (entry :: acc) xs in (remaining, xs) | labels -> let children, xs = aux (succ depth) acc labels in let remaining, xs = aux depth children xs in (remaining, xs) in match labels with | [] -> [] | (level, _) :: _ -> labels |> aux level [] |> fst let to_labelled_list toc = let rec aux current_index elements = List.mapi (fun i { content; children } -> let new_index = current_index @ [ i + 1 ] in (new_index, content) :: aux new_index children) elements |> List.flatten in aux [] toc let to_html ?(ol = false) f toc = let ul children = let r = String.concat "" children in if ol then "<ol>" ^ r ^ "</ol>" else "<ul>" ^ r ^ "</ul>" in let li children = "<li>" ^ children ^ "</li>" in let a = Format.asprintf "<a href=\"#%s\">%s</a>" in let rec aux = function | [] -> None | xs -> xs |> List.map (fun { content = id, title; children } -> let content = a id (f title) in let children = Option.fold ~none:"" ~some:ul (aux children) in li @@ content ^ children) |> Option.some in aux toc |> Option.map ul end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>