From fd1918c04e0d70bf784c4176595e36c9c26e05b2 Mon Sep 17 00:00:00 2001 From: Yawar Amin Date: Wed, 28 Aug 2024 15:20:29 -0400 Subject: [PATCH] Extract XML mode check function --- pure-html/pure_html.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pure-html/pure_html.ml b/pure-html/pure_html.ml index 154cdd4..798c782 100644 --- a/pure-html/pure_html.ml +++ b/pure-html/pure_html.ml @@ -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; _ } -> @@ -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 "\n"; p "<"; p name;