Skip to content

Commit 38373ea

Browse files
authored
Append doctype tag on html lowercase (#136)
1 parent 3383037 commit 38373ea

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/reactDom/src/ReactDOM.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ let render_to_string ~mode element =
8383
when Html.is_self_closing_tag tag ->
8484
is_root.contents <- false;
8585
Printf.sprintf "<%s%s />" tag (attributes_to_string attributes)
86+
| Lower_case_element { tag; attributes; children }
87+
when String.equal tag "html" ->
88+
is_root.contents <- false;
89+
Printf.sprintf "<!DOCTYPE html><%s%s>%s</%s>" tag
90+
(attributes_to_string attributes)
91+
(children |> List.map render_element |> String.concat "")
92+
tag
8693
| Lower_case_element { tag; attributes; children } ->
8794
is_root.contents <- false;
8895
Printf.sprintf "<%s%s>%s</%s>" tag

packages/reactDom/test/test_renderToStaticMarkup.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ let single_empty_tag () =
55
let div = React.createElement "div" [] [] in
66
assert_string (ReactDOM.renderToStaticMarkup div) "<div></div>"
77

8+
let html_doctype () =
9+
let app = React.createElement "html" [] [] in
10+
assert_string
11+
(ReactDOM.renderToStaticMarkup app)
12+
"<!DOCTYPE html><html></html>"
13+
814
let empty_string_attribute () =
915
let div = React.createElement "div" [ React.JSX.String ("class", "") ] [] in
1016
assert_string (ReactDOM.renderToStaticMarkup div) "<div class=\"\"></div>"
@@ -321,6 +327,7 @@ let case title fn = Alcotest_lwt.test_case_sync title `Quick fn
321327
let tests =
322328
( "renderToStaticMarkup",
323329
[
330+
case "html_doctype" html_doctype;
324331
case "single_empty_tag" single_empty_tag;
325332
case "empty_string_attribute" empty_string_attribute;
326333
case "bool_attributes" bool_attributes;

0 commit comments

Comments
 (0)