diff --git a/src/common.ml b/src/common.ml index eed3f1d..80fef7d 100644 --- a/src/common.ml +++ b/src/common.ml @@ -179,12 +179,12 @@ let signal_to_string = function end | Some name -> match d.public_identifier, d.system_identifier with - | None, None -> name + | None, None -> " " ^ name | Some p, None -> Printf.sprintf " %s PUBLIC \"%s\"" name p | None, Some s -> Printf.sprintf " %s SYSTEM \"%s\"" name s | Some p, Some s -> Printf.sprintf " %s PUBLIC \"%s\" \"%s\"" name p s in - Printf.sprintf "" text + Printf.sprintf "" text | `Start_element (name, attributes) -> let name_to_string = function diff --git a/src/html_writer.ml b/src/html_writer.ml index 3e7e4c8..b840db8 100644 --- a/src/html_writer.ml +++ b/src/html_writer.ml @@ -151,10 +151,10 @@ let write ?(escape_attribute=escape_attribute) ?(escape_text=escape_text) signal | `PI (target, s) -> emit_list [""] throw e k - | `Doctype {doctype_name = Some name} -> - emit_list [""] throw e k + | `Doctype _ as doctype -> + emit_list [signal_to_string doctype] throw e k - | `Doctype _ | `Xml _ -> + | `Xml _ -> next_signal throw e k end diff --git a/test/test_html_writer.ml b/test/test_html_writer.ml index c551f03..fc0096f 100644 --- a/test/test_html_writer.ml +++ b/test/test_html_writer.ml @@ -36,10 +36,10 @@ let tests = [ raw_text = None; force_quirks = false} in - expect "doctype" [`Doctype doctype] [S ""]; + expect "doctype" [`Doctype doctype] [S ""]; let doctype = {doctype with doctype_name = None} in - expect "bad doctype" [`Doctype doctype] []); + expect "bad doctype" [`Doctype doctype] [S ""]); ("html.writer.comment" >:: fun _ -> expect "comment" [`Comment "foo"] [S ""]); diff --git a/test/test_integration.ml b/test/test_integration.ml index 1fe2cc8..3eef24d 100644 --- a/test/test_integration.ml +++ b/test/test_integration.ml @@ -90,5 +90,18 @@ let tests = [ stream |> tree ~text:(fun _ -> ()) ~element:(fun _ _ _ -> ()) in assert_equal ~msg:"fi" (assemble ()) (Some ()); - assert_equal ~msg:"fi" (assemble ()) None) + assert_equal ~msg:"fi" (assemble ()) None); + + ("integration.doctype.roundtrip" >:: fun _ -> + ({||}) + |> string + |> parse_html + |> signals + |> write_html + |> to_string + |> assert_equal + ({||} ^ + {||})) ]