1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 12:48:11 +00:00

Revert "LibHTML: Rename parse_html() => parse_html_document()"

This reverts commit f6439789db.
Oops, I committed unrelated changes here, let me clean that up..
This commit is contained in:
Andreas Kling 2019-11-06 20:51:07 +01:00
parent f6439789db
commit f5cf8d4ad8
7 changed files with 38 additions and 41 deletions

View file

@ -80,7 +80,7 @@ int main(int argc, char* argv[])
ASSERT(success); ASSERT(success);
String html = md_document.render_to_html(); String html = md_document.render_to_html();
auto html_document = parse_html_document(html); auto html_document = parse_html(html);
html_view->set_document(html_document); html_view->set_document(html_document);
String page_and_section = model->page_and_section(tree_view->selection().first()); String page_and_section = model->page_and_section(tree_view->selection().first());

View file

@ -1,6 +1,4 @@
#include "IRCLogBuffer.h" #include "IRCLogBuffer.h"
#include <AK/StringBuilder.h>
#include <LibHTML/DOM/DocumentFragment.h>
#include <LibHTML/DOM/DocumentType.h> #include <LibHTML/DOM/DocumentType.h>
#include <LibHTML/DOM/ElementFactory.h> #include <LibHTML/DOM/ElementFactory.h>
#include <LibHTML/DOM/HTMLBodyElement.h> #include <LibHTML/DOM/HTMLBodyElement.h>
@ -35,43 +33,42 @@ IRCLogBuffer::~IRCLogBuffer()
{ {
} }
static String timestamp_string()
{
auto now = time(nullptr);
auto* tm = localtime(&now);
return String::format("%02u:%02u:%02u ", tm->tm_hour, tm->tm_min, tm->tm_sec);
}
void IRCLogBuffer::add_message(char prefix, const String& name, const String& text, Color color) void IRCLogBuffer::add_message(char prefix, const String& name, const String& text, Color color)
{ {
auto nick_string = String::format("&lt;%c%s&gt; ", prefix ? prefix : ' ', name.characters()); auto message_element = create_element(document(), "div");
auto html = String::format( message_element->set_attribute("style", String::format("color: %s;", color.to_string().characters()));
"<div style=\"color: %s\">" auto timestamp_element = create_element(document(), "span");
"<span>%s</span>" auto now = time(nullptr);
"<b>%s</b>" auto* tm = localtime(&now);
"<span>%s</span>" auto timestamp_string = String::format("%02u:%02u:%02u ", tm->tm_hour, tm->tm_min, tm->tm_sec);
"</div>", timestamp_element->append_child(adopt(*new Text(document(), timestamp_string)));
color.to_string().characters(), auto nick_element = create_element(document(), "b");
timestamp_string().characters(), nick_element->append_child(*new Text(document(), String::format("<%c%s> ", prefix ? prefix : ' ', name.characters())));
nick_string.characters(), auto text_element = create_element(document(), "span");
text.characters()); text_element->append_child(*new Text(document(), text));
auto fragment = parse_html_fragment(*m_document, html); message_element->append_child(timestamp_element);
m_container_element->append_child(fragment->remove_child(*fragment->first_child())); message_element->append_child(nick_element);
message_element->append_child(text_element);
m_container_element->append_child(message_element);
m_document->force_layout(); m_document->force_layout();
} }
void IRCLogBuffer::add_message(const String& text, Color color) void IRCLogBuffer::add_message(const String& text, Color color)
{ {
auto html = String::format( auto message_element = create_element(document(), "div");
"<div style=\"color: %s\">" message_element->set_attribute("style", String::format("color: %s;", color.to_string().characters()));
"<span>%s</span>" auto timestamp_element = create_element(document(), "span");
"<span>%s</span>" auto now = time(nullptr);
"</div>", auto* tm = localtime(&now);
color.to_string().characters(), auto timestamp_string = String::format("%02u:%02u:%02u ", tm->tm_hour, tm->tm_min, tm->tm_sec);
timestamp_string().characters(), timestamp_element->append_child(adopt(*new Text(document(), timestamp_string)));
text.characters()); auto text_element = create_element(document(), "span");
auto fragment = parse_html_fragment(*m_document, html); text_element->append_child(*new Text(document(), text));
m_container_element->append_child(fragment->remove_child(*fragment->first_child())); message_element->append_child(timestamp_element);
message_element->append_child(text_element);
m_container_element->append_child(message_element);
m_document->force_layout(); m_document->force_layout();
} }

View file

@ -121,7 +121,7 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
auto html_text = man_document.render_to_html(); auto html_text = man_document.render_to_html();
auto html_document = parse_html_document(html_text); auto html_document = parse_html(html_text);
if (!html_document) { if (!html_document) {
dbg() << "failed to parse HTML"; dbg() << "failed to parse HTML";
return; return;

View file

@ -314,7 +314,7 @@ void HtmlView::load(const URL& url)
if (url.path().ends_with(".png")) { if (url.path().ends_with(".png")) {
document = create_image_document(data, url); document = create_image_document(data, url);
} else { } else {
document = parse_html_document(data, url); document = parse_html(data, url);
} }
ASSERT(document); ASSERT(document);
set_document(document); set_document(document);

View file

@ -34,7 +34,7 @@ static bool is_self_closing_tag(const StringView& tag_name)
|| tag_name == "wbr"; || tag_name == "wbr";
} }
static bool parse_html_document(const StringView& html, Document& document, ParentNode& root) static bool parse_html(const StringView& html, Document& document, ParentNode& root)
{ {
NonnullRefPtrVector<ParentNode> node_stack; NonnullRefPtrVector<ParentNode> node_stack;
node_stack.append(root); node_stack.append(root);
@ -313,17 +313,17 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
RefPtr<DocumentFragment> parse_html_fragment(Document& document, const StringView& html) RefPtr<DocumentFragment> parse_html_fragment(Document& document, const StringView& html)
{ {
auto fragment = adopt(*new DocumentFragment(document)); auto fragment = adopt(*new DocumentFragment(document));
if (!parse_html_document(html, document, *fragment)) if (!parse_html(html, document, *fragment))
return nullptr; return nullptr;
return fragment; return fragment;
} }
NonnullRefPtr<Document> parse_html_document(const StringView& html, const URL& url) NonnullRefPtr<Document> parse_html(const StringView& html, const URL& url)
{ {
auto document = adopt(*new Document); auto document = adopt(*new Document);
document->set_url(url); document->set_url(url);
bool success = parse_html_document(html, *document, *document); bool success = parse_html(html, *document, *document);
ASSERT(success); ASSERT(success);
document->fixup(); document->fixup();

View file

@ -5,5 +5,5 @@
class DocumentFragment; class DocumentFragment;
NonnullRefPtr<Document> parse_html_document(const StringView&, const URL& = URL()); NonnullRefPtr<Document> parse_html(const StringView&, const URL& = URL());
RefPtr<DocumentFragment> parse_html_fragment(Document&, const StringView&); RefPtr<DocumentFragment> parse_html_fragment(Document&, const StringView&);

View file

@ -34,7 +34,7 @@ int main(int argc, char** argv)
} }
String html = String::copy(f->read_all()); String html = String::copy(f->read_all());
auto document = parse_html_document(html); auto document = parse_html(html);
auto window = GWindow::construct(); auto window = GWindow::construct();
auto widget = HtmlView::construct(); auto widget = HtmlView::construct();