@@ -1764,21 +1764,26 @@ pub inline fn domImplementationCreateDocumentType(
17641764}
17651765
17661766pub inline fn domImplementationCreateHTMLDocument (title : ? []const u8 ) ! * DocumentHTML {
1767- var doc : ? * Document = undefined ;
1768- const err = c .dom_implementation_create_document (
1769- c .DOM_IMPLEMENTATION_HTML ,
1770- null ,
1771- null ,
1772- null ,
1773- null ,
1774- null ,
1775- & doc ,
1776- );
1777- try DOMErr (err );
1778-
1779- const doc_html = @as (* DocumentHTML , @ptrCast (doc .? ));
1767+ const doc_html = try documentCreateDocument (title );
1768+ const doc = documentHTMLToDocument (doc_html );
1769+
1770+ // add hierarchy: html, head, body.
1771+ const html = try documentCreateElement (doc , "html" );
1772+ _ = try nodeAppendChild (documentToNode (doc ), elementToNode (html ));
1773+
1774+ const head = try documentCreateElement (doc , "head" );
1775+ _ = try nodeAppendChild (elementToNode (html ), elementToNode (head ));
1776+
1777+ if (title ) | t | {
1778+ try documentHTMLSetTitle (doc_html , t );
1779+ const htitle = try documentCreateElement (doc , "title" );
1780+ const txt = try documentCreateTextNode (doc , t );
1781+ _ = try nodeAppendChild (elementToNode (htitle ), @as (* Node , @ptrCast (txt )));
1782+ _ = try nodeAppendChild (elementToNode (head ), elementToNode (htitle ));
1783+ }
17801784
1781- if (title ) | t | try documentHTMLSetTitle (doc_html , t );
1785+ const body = try documentCreateElement (doc , "body" );
1786+ _ = try nodeAppendChild (elementToNode (html ), elementToNode (body ));
17821787
17831788 return doc_html ;
17841789}
@@ -1841,6 +1846,23 @@ pub inline fn documentSetInputEncoding(doc: *Document, enc: []const u8) !void {
18411846 try DOMErr (err );
18421847}
18431848
1849+ pub inline fn documentCreateDocument (title : ? []const u8 ) ! * DocumentHTML {
1850+ var doc : ? * Document = undefined ;
1851+ const err = c .dom_implementation_create_document (
1852+ c .DOM_IMPLEMENTATION_HTML ,
1853+ null ,
1854+ null ,
1855+ null ,
1856+ null ,
1857+ null ,
1858+ & doc ,
1859+ );
1860+ try DOMErr (err );
1861+ const doc_html = @as (* DocumentHTML , @ptrCast (doc .? ));
1862+ if (title ) | t | try documentHTMLSetTitle (doc_html , t );
1863+ return doc_html ;
1864+ }
1865+
18441866pub inline fn documentCreateElement (doc : * Document , tag_name : []const u8 ) ! * Element {
18451867 var elem : ? * Element = undefined ;
18461868 const err = documentVtable (doc ).dom_document_create_element .? (doc , try strFromData (tag_name ), & elem );
0 commit comments