mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 07:04:59 +00:00
LibWeb: Add DOMParser
This allows you to invoke the HTML document parser and retrieve a document as though it was loaded as a web page, minus any scripting ability. This does not currently support XML parsing. This is used by YouTube (or more accurately, Web Components Polyfills) to polyfill templates.
This commit is contained in:
parent
0ea50d44bf
commit
f7ad8c0f94
6 changed files with 93 additions and 0 deletions
41
Userland/Libraries/LibWeb/HTML/DOMParser.cpp
Normal file
41
Userland/Libraries/LibWeb/HTML/DOMParser.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/DOMParser.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
DOMParser::DOMParser()
|
||||
{
|
||||
}
|
||||
|
||||
DOMParser::~DOMParser()
|
||||
{
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-domparser-parsefromstring
|
||||
NonnullRefPtr<DOM::Document> DOMParser::parse_from_string(String const& string, String const& type)
|
||||
{
|
||||
// FIXME: Pass in this's relevant global object's associated Document's URL.
|
||||
auto document = DOM::Document::create();
|
||||
document->set_content_type(type);
|
||||
|
||||
// NOTE: This isn't a case insensitive match since the DOMParserSupportedType enum enforces an all lowercase type.
|
||||
if (type == "text/html") {
|
||||
// FIXME: Set document's type to "html".
|
||||
HTMLDocumentParser parser(document, string, "UTF-8");
|
||||
// FIXME: This is to match the default URL. Instead, pass in this's relevant global object's associated Document's URL.
|
||||
parser.run("about:blank");
|
||||
} else {
|
||||
dbgln("DOMParser::parse_from_string: Unimplemented parser for type: {}", type);
|
||||
TODO();
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue