mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb: Teach HtmlView how to render Markdown files :^)
This commit is contained in:
parent
97adcde36e
commit
f1708b3832
Notes:
sideshowbarker
2024-07-19 06:44:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f1708b3832d
3 changed files with 14 additions and 2 deletions
|
@ -8,7 +8,7 @@ OBJS = \
|
|||
|
||||
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
|
||||
../../Libraries/LibWeb/CSS/PropertyID.h:
|
||||
|
|
|
@ -11,6 +11,6 @@ OBJS = \
|
|||
|
||||
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
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/ImageDecoder.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibMarkdown/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLAnchorElement.h>
|
||||
|
@ -321,6 +322,15 @@ void HtmlView::reload()
|
|||
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)
|
||||
{
|
||||
auto document = adopt(*new Document(url));
|
||||
|
@ -420,6 +430,8 @@ void HtmlView::load(const URL& url)
|
|||
document = create_image_document(data, url);
|
||||
} else if (url.path().ends_with(".txt")) {
|
||||
document = create_text_document(data, url);
|
||||
} else if (url.path().ends_with(".md")) {
|
||||
document = create_markdown_document(data, url);
|
||||
} else {
|
||||
String encoding = "utf-8";
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue