Skip to content

Commit

Permalink
Add concat function to join nodes with a separator
Browse files Browse the repository at this point in the history
  • Loading branch information
yawaramin committed Jan 17, 2025
1 parent b0798bd commit ed9a3dd
Show file tree
Hide file tree
Showing 4 changed files with 378 additions and 364 deletions.
5 changes: 5 additions & 0 deletions pure-html/pure_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@ module HTML = struct
let wbr = void_tag "wbr"
end

let rec concat sep = function
| [] -> HTML.null []
| [node] -> node
| node :: nodes -> HTML.null [node; sep; concat sep nodes]

module SVG = struct
(* Attributes *)
let d fmt = string_attr "d" fmt
Expand Down
6 changes: 6 additions & 0 deletions pure-html/pure_html.mli
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ val comment : string -> node
(** A comment that will be embedded in the rendered HTML, i.e.
[<!-- comment -->]. The text is HTML-escaped. *)

val concat : node -> node list -> node
(** [concat node list] is the [list] of nodes joined together into a single
node, with each element separated by [node].
@since 3.10.0 *)

(** {2 Accessors for tags} *)

val ( +@ ) : node -> attr -> node
Expand Down
14 changes: 14 additions & 0 deletions test/pure_html_test.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@



🔎 Concat HTML - empty list



🔎 Concat HTML - singleton list
<a href="/">Home</a>



🔎 Concat HTML - list
<a href="/">Home</a>, <a href="/a">a</a>


🔎 SVG
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
Expand Down Expand Up @@ -502,6 +515,7 @@


🔎 RSS
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>NASA Space Station News</title>
Expand Down
Loading

0 comments on commit ed9a3dd

Please sign in to comment.