mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:28:11 +00:00
LibWeb: Teach HtmlView how to render Markdown files :^)
This commit is contained in:
parent
97adcde36e
commit
f1708b3832
3 changed files with 14 additions and 2 deletions
|
@ -8,7 +8,7 @@ OBJS = \
|
||||||
|
|
||||||
PROGRAM = Browser
|
PROGRAM = Browser
|
||||||
|
|
||||||
LIB_DEPS = Web JS TextCodec GUI Gfx IPC Protocol Core
|
LIB_DEPS = Web JS Markdown TextCodec GUI Gfx IPC Protocol Core
|
||||||
|
|
||||||
main.cpp: ../../Libraries/LibWeb/CSS/PropertyID.h
|
main.cpp: ../../Libraries/LibWeb/CSS/PropertyID.h
|
||||||
../../Libraries/LibWeb/CSS/PropertyID.h:
|
../../Libraries/LibWeb/CSS/PropertyID.h:
|
||||||
|
|
|
@ -11,6 +11,6 @@ OBJS = \
|
||||||
|
|
||||||
PROGRAM = IRCClient
|
PROGRAM = IRCClient
|
||||||
|
|
||||||
LIB_DEPS = Web TextCodec JS GUI Gfx Protocol IPC Thread Pthread Core
|
LIB_DEPS = Web TextCodec JS Markdown GUI Gfx Protocol IPC Thread Pthread Core
|
||||||
|
|
||||||
include ../../Makefile.common
|
include ../../Makefile.common
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/ImageDecoder.h>
|
#include <LibGfx/ImageDecoder.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
#include <LibMarkdown/Document.h>
|
||||||
#include <LibWeb/DOM/Element.h>
|
#include <LibWeb/DOM/Element.h>
|
||||||
#include <LibWeb/DOM/ElementFactory.h>
|
#include <LibWeb/DOM/ElementFactory.h>
|
||||||
#include <LibWeb/DOM/HTMLAnchorElement.h>
|
#include <LibWeb/DOM/HTMLAnchorElement.h>
|
||||||
|
@ -321,6 +322,15 @@ void HtmlView::reload()
|
||||||
load(main_frame().document()->url());
|
load(main_frame().document()->url());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RefPtr<Document> create_markdown_document(const ByteBuffer& data, const URL& url)
|
||||||
|
{
|
||||||
|
Markdown::Document markdown_document;
|
||||||
|
if (!markdown_document.parse(data))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return parse_html_document(markdown_document.render_to_html(), url);
|
||||||
|
}
|
||||||
|
|
||||||
static RefPtr<Document> create_text_document(const ByteBuffer& data, const URL& url)
|
static RefPtr<Document> create_text_document(const ByteBuffer& data, const URL& url)
|
||||||
{
|
{
|
||||||
auto document = adopt(*new Document(url));
|
auto document = adopt(*new Document(url));
|
||||||
|
@ -420,6 +430,8 @@ void HtmlView::load(const URL& url)
|
||||||
document = create_image_document(data, url);
|
document = create_image_document(data, url);
|
||||||
} else if (url.path().ends_with(".txt")) {
|
} else if (url.path().ends_with(".txt")) {
|
||||||
document = create_text_document(data, url);
|
document = create_text_document(data, url);
|
||||||
|
} else if (url.path().ends_with(".md")) {
|
||||||
|
document = create_markdown_document(data, url);
|
||||||
} else {
|
} else {
|
||||||
String encoding = "utf-8";
|
String encoding = "utf-8";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue