Skip to content

Commit

Permalink
Extract XML mode check function
Browse files Browse the repository at this point in the history
  • Loading branch information
yawaramin committed Aug 28, 2024
1 parent 4de8dc9 commit fd1918c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pure-html/pure_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ let write_attr ~xml p = function
p value;
p {|"|}

let xml_mode xml name =
match xml, name with
| true, _ | _, ("math" | "svg") -> true
| _ -> false

(* Loosely based on https://www.w3.org/TR/DOM-Parsing/ *)
let rec write_tag ~xml p = function
| Tag { name = ""; children = Some children; _ } ->
Expand All @@ -56,13 +61,13 @@ let rec write_tag ~xml p = function
List.iter (write_attr ~xml p) attrs;
p " />"
| Tag { name; attrs; children = None } ->
let xml = name = "math" || name = "svg" || xml in
let xml = xml_mode xml name in
p "<";
p name;
List.iter (write_attr ~xml p) attrs;
p (if xml then " />" else ">")
| Tag { name; attrs; children = Some children } ->
let xml = name = "math" || name = "svg" || xml in
let xml = xml_mode xml name in
if name = "html" then p "<!DOCTYPE html>\n";
p "<";
p name;
Expand Down

0 comments on commit fd1918c

Please sign in to comment.