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:
parent
b9493ba783
commit
6ec625d6f3
5 changed files with 16 additions and 16 deletions
|
@ -104,7 +104,6 @@ cp ../Servers/AudioServer/AudioServer mnt/bin/AudioServer
|
||||||
cp ../Servers/TTYServer/TTYServer mnt/bin/TTYServer
|
cp ../Servers/TTYServer/TTYServer mnt/bin/TTYServer
|
||||||
cp ../Servers/TelnetServer/TelnetServer mnt/bin/TelnetServer
|
cp ../Servers/TelnetServer/TelnetServer mnt/bin/TelnetServer
|
||||||
cp ../Shell/Shell mnt/bin/Shell
|
cp ../Shell/Shell mnt/bin/Shell
|
||||||
cp ../Libraries/LibHTML/tho mnt/bin/tho
|
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|
||||||
echo -n "installing shortcuts... "
|
echo -n "installing shortcuts... "
|
||||||
|
|
|
@ -2,12 +2,9 @@ include ../../Makefile.common
|
||||||
|
|
||||||
LIBRARY = libhtml.a
|
LIBRARY = libhtml.a
|
||||||
|
|
||||||
all: $(LIBRARY) tho
|
all: $(LIBRARY)
|
||||||
|
|
||||||
include Makefile.shared
|
include Makefile.shared
|
||||||
|
|
||||||
tho: $(TEST_OBJS) $(LIBRARY)
|
|
||||||
$(LD) -o $@ $(LDFLAGS) -L. $(TEST_OBJS) -lhtml -lgui -ldraw -lcore -lc
|
|
||||||
|
|
||||||
$(LIBRARY): $(LIBHTML_OBJS)
|
$(LIBRARY): $(LIBHTML_OBJS)
|
||||||
@echo "LIB $@"; $(AR) rcs $@ $(LIBHTML_OBJS)
|
@echo "LIB $@"; $(AR) rcs $@ $(LIBHTML_OBJS)
|
||||||
|
|
|
@ -26,10 +26,7 @@ LIBHTML_OBJS = \
|
||||||
GENERATED_SOURCES = \
|
GENERATED_SOURCES = \
|
||||||
CSS/DefaultStyleSheetSource.cpp
|
CSS/DefaultStyleSheetSource.cpp
|
||||||
|
|
||||||
TEST_OBJS = test.o
|
OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS)
|
||||||
TEST_PROGRAM = tho
|
|
||||||
|
|
||||||
OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS) $(TEST_OBJS)
|
|
||||||
|
|
||||||
LIBRARY = libhtml.a
|
LIBRARY = libhtml.a
|
||||||
DEFINES += -DUSERLAND
|
DEFINES += -DUSERLAND
|
||||||
|
@ -43,5 +40,5 @@ CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSourc
|
||||||
-include $(OBJS:%.o=%.d)
|
-include $(OBJS:%.o=%.d)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
|
@echo "CLEAN"; rm -f $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ clean:
|
||||||
|
|
||||||
$(APPS) : % : %.o $(OBJS)
|
$(APPS) : % : %.o $(OBJS)
|
||||||
@echo "LD $@"
|
@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
|
%.o: %.cpp
|
||||||
@echo "CXX $<"
|
@echo "CXX $<"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <LibHTML/HtmlView.h>
|
#include <LibHTML/HtmlView.h>
|
||||||
#include <LibHTML/Layout/LayoutBlock.h>
|
#include <LibHTML/Layout/LayoutBlock.h>
|
||||||
#include <LibHTML/Layout/LayoutInline.h>
|
#include <LibHTML/Layout/LayoutInline.h>
|
||||||
|
#include <LibHTML/Layout/LayoutNode.h>
|
||||||
#include <LibHTML/Parser/CSSParser.h>
|
#include <LibHTML/Parser/CSSParser.h>
|
||||||
#include <LibHTML/Parser/HTMLParser.h>
|
#include <LibHTML/Parser/HTMLParser.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -15,26 +16,32 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GApplication app(argc, argv);
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
auto f = CFile::construct(argc == 1 ? "/home/anon/small.html" : argv[1]);
|
auto f = CFile::construct();
|
||||||
if (!f->open(CIODevice::ReadOnly)) {
|
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());
|
fprintf(stderr, "Error: %s\n", f->error_string());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char default_stylesheet_source[];
|
extern const char default_stylesheet_source[];
|
||||||
String css = default_stylesheet_source;
|
String css = default_stylesheet_source;
|
||||||
|
|
||||||
auto sheet = parse_css(css);
|
auto sheet = parse_css(css);
|
||||||
dump_sheet(sheet);
|
|
||||||
|
|
||||||
String html = String::copy(f->read_all());
|
String html = String::copy(f->read_all());
|
||||||
auto document = parse_html(html);
|
auto document = parse_html(html);
|
||||||
dump_tree(document);
|
document->normalize();
|
||||||
document->add_sheet(*sheet);
|
document->add_sheet(*sheet);
|
||||||
|
|
||||||
auto window = GWindow::construct();
|
auto window = GWindow::construct();
|
||||||
auto widget = HtmlView::construct();
|
auto widget = HtmlView::construct();
|
||||||
widget->set_document(document);
|
widget->set_document(document);
|
||||||
|
window->set_title("HTML");
|
||||||
window->set_main_widget(widget);
|
window->set_main_widget(widget);
|
||||||
window->show();
|
window->show();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue