DOMParser.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/HTML/DOMParser.h>
  7. #include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
  8. namespace Web::HTML {
  9. DOMParser::DOMParser()
  10. {
  11. }
  12. DOMParser::~DOMParser()
  13. {
  14. }
  15. // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring
  16. NonnullRefPtr<DOM::Document> DOMParser::parse_from_string(String const& string, String const& type)
  17. {
  18. // FIXME: Pass in this's relevant global object's associated Document's URL.
  19. auto document = DOM::Document::create();
  20. document->set_content_type(type);
  21. // NOTE: This isn't a case insensitive match since the DOMParserSupportedType enum enforces an all lowercase type.
  22. if (type == "text/html") {
  23. // FIXME: Set document's type to "html".
  24. HTMLDocumentParser parser(document, string, "UTF-8");
  25. // FIXME: This is to match the default URL. Instead, pass in this's relevant global object's associated Document's URL.
  26. parser.run("about:blank");
  27. } else {
  28. dbgln("DOMParser::parse_from_string: Unimplemented parser for type: {}", type);
  29. TODO();
  30. }
  31. return document;
  32. }
  33. }