Skip to content

Commit

Permalink
Append doctype tag on html lowercase (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx authored Jul 18, 2024
1 parent 3383037 commit 38373ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/reactDom/src/ReactDOM.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ let render_to_string ~mode element =
when Html.is_self_closing_tag tag ->
is_root.contents <- false;
Printf.sprintf "<%s%s />" tag (attributes_to_string attributes)
| Lower_case_element { tag; attributes; children }
when String.equal tag "html" ->
is_root.contents <- false;
Printf.sprintf "<!DOCTYPE html><%s%s>%s</%s>" tag
(attributes_to_string attributes)
(children |> List.map render_element |> String.concat "")
tag
| Lower_case_element { tag; attributes; children } ->
is_root.contents <- false;
Printf.sprintf "<%s%s>%s</%s>" tag
Expand Down
7 changes: 7 additions & 0 deletions packages/reactDom/test/test_renderToStaticMarkup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ let single_empty_tag () =
let div = React.createElement "div" [] [] in
assert_string (ReactDOM.renderToStaticMarkup div) "<div></div>"

let html_doctype () =
let app = React.createElement "html" [] [] in
assert_string
(ReactDOM.renderToStaticMarkup app)
"<!DOCTYPE html><html></html>"

let empty_string_attribute () =
let div = React.createElement "div" [ React.JSX.String ("class", "") ] [] in
assert_string (ReactDOM.renderToStaticMarkup div) "<div class=\"\"></div>"
Expand Down Expand Up @@ -321,6 +327,7 @@ let case title fn = Alcotest_lwt.test_case_sync title `Quick fn
let tests =
( "renderToStaticMarkup",
[
case "html_doctype" html_doctype;
case "single_empty_tag" single_empty_tag;
case "empty_string_attribute" empty_string_attribute;
case "bool_attributes" bool_attributes;
Expand Down

0 comments on commit 38373ea

Please sign in to comment.