diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp
index a9589c0686..8b4af6a0bd 100644
--- a/Libraries/LibHTML/DOM/Document.cpp
+++ b/Libraries/LibHTML/DOM/Document.cpp
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -36,8 +37,8 @@ void Document::fixup()
if (is(first_child()->next_sibling()))
return;
- auto body = adopt(*new HTMLBodyElement(*this, "body"));
- auto html = adopt(*new HTMLHtmlElement(*this, "html"));
+ auto body = create_element(*this, "body");
+ auto html = create_element(*this, "html");
html->append_child(body);
this->donate_all_children_to(body);
this->append_child(html);
diff --git a/Libraries/LibHTML/DOM/ElementFactory.cpp b/Libraries/LibHTML/DOM/ElementFactory.cpp
new file mode 100644
index 0000000000..6ba9595624
--- /dev/null
+++ b/Libraries/LibHTML/DOM/ElementFactory.cpp
@@ -0,0 +1,49 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+NonnullRefPtr create_element(Document& document, const String& tag_name)
+{
+ auto lowercase_tag_name = tag_name.to_lowercase();
+ if (lowercase_tag_name == "a")
+ return adopt(*new HTMLAnchorElement(document, tag_name));
+ if (lowercase_tag_name == "html")
+ return adopt(*new HTMLHtmlElement(document, tag_name));
+ if (lowercase_tag_name == "head")
+ return adopt(*new HTMLHeadElement(document, tag_name));
+ if (lowercase_tag_name == "body")
+ return adopt(*new HTMLBodyElement(document, tag_name));
+ if (lowercase_tag_name == "font")
+ return adopt(*new HTMLFontElement(document, tag_name));
+ if (lowercase_tag_name == "hr")
+ return adopt(*new HTMLHRElement(document, tag_name));
+ if (lowercase_tag_name == "style")
+ return adopt(*new HTMLStyleElement(document, tag_name));
+ if (lowercase_tag_name == "title")
+ return adopt(*new HTMLTitleElement(document, tag_name));
+ if (lowercase_tag_name == "link")
+ return adopt(*new HTMLLinkElement(document, tag_name));
+ if (lowercase_tag_name == "img")
+ return adopt(*new HTMLImageElement(document, tag_name));
+ if (lowercase_tag_name == "blink")
+ return adopt(*new HTMLBlinkElement(document, tag_name));
+ if (lowercase_tag_name == "h1"
+ || lowercase_tag_name == "h2"
+ || lowercase_tag_name == "h3"
+ || lowercase_tag_name == "h4"
+ || lowercase_tag_name == "h5"
+ || lowercase_tag_name == "h6") {
+ return adopt(*new HTMLHeadingElement(document, tag_name));
+ }
+ return adopt(*new Element(document, tag_name));
+}
diff --git a/Libraries/LibHTML/DOM/ElementFactory.h b/Libraries/LibHTML/DOM/ElementFactory.h
new file mode 100644
index 0000000000..26e61854f2
--- /dev/null
+++ b/Libraries/LibHTML/DOM/ElementFactory.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include
+
+NonnullRefPtr create_element(Document&, const String& tag_name);
diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared
index e57c9ef9f9..3252e010e3 100644
--- a/Libraries/LibHTML/Makefile.shared
+++ b/Libraries/LibHTML/Makefile.shared
@@ -18,6 +18,7 @@ LIBHTML_OBJS = \
DOM/Document.o \
DOM/Text.o \
DOM/DocumentType.o \
+ DOM/ElementFactory.o \
CSS/Selector.o \
CSS/StyleSheet.o \
CSS/StyleRule.o \
diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp
index 06ae02e88d..a69871c8a0 100644
--- a/Libraries/LibHTML/Parser/HTMLParser.cpp
+++ b/Libraries/LibHTML/Parser/HTMLParser.cpp
@@ -3,59 +3,12 @@
#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
#include
#include
#include
#include
-static NonnullRefPtr create_element(Document& document, const String& tag_name)
-{
- auto lowercase_tag_name = tag_name.to_lowercase();
- if (lowercase_tag_name == "a")
- return adopt(*new HTMLAnchorElement(document, tag_name));
- if (lowercase_tag_name == "html")
- return adopt(*new HTMLHtmlElement(document, tag_name));
- if (lowercase_tag_name == "head")
- return adopt(*new HTMLHeadElement(document, tag_name));
- if (lowercase_tag_name == "body")
- return adopt(*new HTMLBodyElement(document, tag_name));
- if (lowercase_tag_name == "font")
- return adopt(*new HTMLFontElement(document, tag_name));
- if (lowercase_tag_name == "hr")
- return adopt(*new HTMLHRElement(document, tag_name));
- if (lowercase_tag_name == "style")
- return adopt(*new HTMLStyleElement(document, tag_name));
- if (lowercase_tag_name == "title")
- return adopt(*new HTMLTitleElement(document, tag_name));
- if (lowercase_tag_name == "link")
- return adopt(*new HTMLLinkElement(document, tag_name));
- if (lowercase_tag_name == "img")
- return adopt(*new HTMLImageElement(document, tag_name));
- if (lowercase_tag_name == "blink")
- return adopt(*new HTMLBlinkElement(document, tag_name));
- if (lowercase_tag_name == "h1"
- || lowercase_tag_name == "h2"
- || lowercase_tag_name == "h3"
- || lowercase_tag_name == "h4"
- || lowercase_tag_name == "h5"
- || lowercase_tag_name == "h6") {
- return adopt(*new HTMLHeadingElement(document, tag_name));
- }
- return adopt(*new Element(document, tag_name));
-}
-
static bool is_valid_in_attribute_name(char ch)
{
return isalnum(ch) || ch == '_' || ch == '-';