package devkit
Development kit - general purpose library
Install
Dune Dependency
Authors
Maintainers
Sources
devkit-1.20240429.tbz
sha256=222f8ac131b1d970dab7eeb2714bfd6b9338b88b1082e6e01c136ae19e7eaef4
sha512=c9e6d93e3d21e5530c0f4d5baca51bf1f0a5d19248f8af7678d0665bb5cdf295d7aaaaa3e50eb2e44b8720e55097cc675af4dc8ec45acf9da39feb3eae1405d5
doc/src/devkit.core/htmlStream.ml.html
Source file htmlStream.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
(** Stream of html elements *) open Printf open ExtLib include HtmlStream_ragel let show_attrs_quote c a = List.map (fun (k,v) -> sprintf " %s=%c%s%c" k c (Raw.project v) c) a |> String.concat "" let show_raw_quote c elem = match elem with | Tag (name,attrs) -> sprintf "<%s%s>" name (show_attrs_quote c attrs) | Text t -> Raw.project t | Close name -> Printf.sprintf "</%s>" name | Script (attrs, s) -> sprintf "<script%s>%s</script>" (show_attrs_quote c attrs) s | Style (attrs, s) -> sprintf "<style%s>%s</style>" (show_attrs_quote c attrs) s let show_raw' = show_raw_quote '\'' let show_raw = show_raw_quote '"' let attrs_include attrs a = let a = if a |> List.exists (fun (_,v) -> String.contains v ' ') then a |> List.map (fun (k,v) -> Stre.nsplitc v ' ' |> List.map (fun s -> k,s)) |> List.flatten else a in match a with | [] -> true | _ -> let attrs = List.map (fun (k,v) -> (k, Stre.nsplitc (Raw.project v) ' ')) attrs in try List.for_all (fun (k,v) -> List.mem v (List.assoc k attrs)) a with Not_found -> false let tag name ?(a=[]) = function | Tag (name',attrs) when name = name' -> attrs_include attrs a | _ -> false let close name = function Close name' when name = name' -> true | _ -> false let to_text ?(br=false) ?(strip=false) = function | Tag ("br",_) when br -> Some (Raw.inject "\n") | Tag _ -> None | Text x -> Some (if strip then Raw.inject (String.strip (Raw.project x)) else x) | Script _ | Style _ | Close _ -> None (* let make_text l = wrapped_outs (fun out -> List.iter (Option.may (IO.nwrite out) $ Option.map Raw.project $ to_text) l) *) let make_text ?br l = let fold e = let b = Buffer.create 10 in let (_:bool) = Enum.fold (fun s bos -> if not bos && s <> "\n" then Buffer.add_char b ' '; Buffer.add_string b s; s = "\n") true e in Buffer.contents b in List.enum l |> Enum.filter_map (to_text ?br ~strip:true) |> Enum.map Raw.project |> fold |> Raw.inject
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>