1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

Userland+LibHTML: Add the html command

This is a simple command that can be used to display HTML from a given
file, or from the standard input, in an HtmlView. It replaces the `tho`
(test HTML output) command.
This commit is contained in:
Sergey Bugaev 2019-09-25 12:45:47 +03:00 committed by Andreas Kling
parent b9493ba783
commit 6ec625d6f3
5 changed files with 16 additions and 16 deletions

View file

@ -104,7 +104,6 @@ cp ../Servers/AudioServer/AudioServer mnt/bin/AudioServer
cp ../Servers/TTYServer/TTYServer mnt/bin/TTYServer
cp ../Servers/TelnetServer/TelnetServer mnt/bin/TelnetServer
cp ../Shell/Shell mnt/bin/Shell
cp ../Libraries/LibHTML/tho mnt/bin/tho
echo "done"
echo -n "installing shortcuts... "

View file

@ -2,12 +2,9 @@ include ../../Makefile.common
LIBRARY = libhtml.a
all: $(LIBRARY) tho
all: $(LIBRARY)
include Makefile.shared
tho: $(TEST_OBJS) $(LIBRARY)
$(LD) -o $@ $(LDFLAGS) -L. $(TEST_OBJS) -lhtml -lgui -ldraw -lcore -lc
$(LIBRARY): $(LIBHTML_OBJS)
@echo "LIB $@"; $(AR) rcs $@ $(LIBHTML_OBJS)

View file

@ -26,10 +26,7 @@ LIBHTML_OBJS = \
GENERATED_SOURCES = \
CSS/DefaultStyleSheetSource.cpp
TEST_OBJS = test.o
TEST_PROGRAM = tho
OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS) $(TEST_OBJS)
OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS)
LIBRARY = libhtml.a
DEFINES += -DUSERLAND
@ -43,5 +40,5 @@ CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSourc
-include $(OBJS:%.o=%.d)
clean:
@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
@echo "CLEAN"; rm -f $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)

View file

@ -19,7 +19,7 @@ clean:
$(APPS) : % : %.o $(OBJS)
@echo "LD $@"
@$(LD) -o $@ $(LDFLAGS) $< -lc -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown
@$(LD) -o $@ $(LDFLAGS) $< -lc -lhtml -lgui -ldraw -laudio -lipc -lthread -lcore -lpcidb -lmarkdown
%.o: %.cpp
@echo "CXX $<"

View file

@ -7,6 +7,7 @@
#include <LibHTML/HtmlView.h>
#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/Layout/LayoutInline.h>
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/Parser/CSSParser.h>
#include <LibHTML/Parser/HTMLParser.h>
#include <stdio.h>
@ -15,26 +16,32 @@ int main(int argc, char** argv)
{
GApplication app(argc, argv);
auto f = CFile::construct(argc == 1 ? "/home/anon/small.html" : argv[1]);
if (!f->open(CIODevice::ReadOnly)) {
auto f = CFile::construct();
bool success;
if (argc < 2) {
success = f->open(STDIN_FILENO, CIODevice::OpenMode::ReadOnly, CFile::ShouldCloseFileDescription::No);
} else {
f->set_filename(argv[1]);
success = f->open(CIODevice::OpenMode::ReadOnly);
}
if (!success) {
fprintf(stderr, "Error: %s\n", f->error_string());
return 1;
}
extern const char default_stylesheet_source[];
String css = default_stylesheet_source;
auto sheet = parse_css(css);
dump_sheet(sheet);
String html = String::copy(f->read_all());
auto document = parse_html(html);
dump_tree(document);
document->normalize();
document->add_sheet(*sheet);
auto window = GWindow::construct();
auto widget = HtmlView::construct();
widget->set_document(document);
window->set_title("HTML");
window->set_main_widget(widget);
window->show();