From 5f591740874a2e8a61e36cbb7461a7898932c2df Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 29 Mar 2022 16:42:02 -0400 Subject: [PATCH] add html.to_string_l --- src/Tiny_httpd_html.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Tiny_httpd_html.ml b/src/Tiny_httpd_html.ml index 52383ebd..6188fa29 100644 --- a/src/Tiny_httpd_html.ml +++ b/src/Tiny_httpd_html.ml @@ -19,6 +19,15 @@ let to_string ?(top=false) (self:elt) : string = self out; Out.to_string out +(** Convert a list of HTML elements to a string. + This is designed for fragments of HTML that are to be injected inside + a bigger context, as it's invalid to have multiple elements at the toplevel + of a HTML document. *) +let to_string_l (l:elt list) = + let out = Out.create () in + List.iter (fun f -> f out; Out.add_format_nl out) l; + Out.to_string out + let to_string_top = to_string ~top:true (** Convert a HTML element to a stream. This might just convert