Skip to content

Commit

Permalink
Fix handling of DOCTYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Sep 17, 2018
1 parent bf0ce7a commit c7639aa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utility.ml
Expand Up @@ -318,11 +318,16 @@ let pretty_print signals =
[`Text [indent (indentation - 1)]; signal; `Text ["\n"]]
(flow (indentation - 1)) throw e k

| _ ->
| `Start_element _ | `Text _ ->
push signals signal;
list
[`Text [indent indentation]]
(phrasing indentation 0) throw e k

| _ ->
list
[signal]
(flow indentation) throw e k
end

and phrasing indentation phrasing_nesting_level throw e k =
Expand Down
41 changes: 41 additions & 0 deletions test/test_utility.ml
Expand Up @@ -8,6 +8,14 @@ open Markup__Common
open Markup
module Kstream = Markup__Kstream

let doctype =
`Doctype
{Markup.doctype_name = Some "html";
public_identifier = None;
system_identifier = None;
raw_text = None;
force_quirks = false}

let start_element name = `Start_element ((Markup.Ns.html, name), [])

let ok = wrong_k "failed"
Expand Down Expand Up @@ -134,6 +142,19 @@ let tests = [
`End_element;
`End_element]);

("utility.trim.doctype" >:: fun _ ->
[doctype;
`Text ["\n"];
start_element "div";
`End_element]
|> of_list
|> trim
|> to_list
|> assert_equal [
doctype;
start_element "div";
`End_element]);

("utility.normalize_text" >:: fun _ ->
[`Text [""];
start_element "a";
Expand Down Expand Up @@ -183,4 +204,24 @@ let tests = [
`Text ["\n"];
`End_element;
`Text ["\n"]]);

("utility.pretty_print.doctype" >:: fun _ ->
[doctype;
start_element "div";
start_element "p";
`End_element;
`End_element]
|> of_list
|> pretty_print
|> to_list
|> assert_equal [
doctype;
start_element "div";
`Text ["\n"; " "];
start_element "p";
`Text ["\n"; " "];
`End_element;
`Text ["\n"];
`End_element;
`Text ["\n"]]);
]

0 comments on commit c7639aa

Please sign in to comment.