diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-10 20:51:35 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-10 22:32:12 +0200 |
commit | f1708b3832d03fc4f4d985f93c89329b5efa78a5 (patch) | |
tree | eb04c8ad71873ba48df84f258402a2a731d4ed72 /Libraries | |
parent | 97adcde36ea642e4facf561cb556cfbb23e7ad0c (diff) | |
download | serenity-f1708b3832d03fc4f4d985f93c89329b5efa78a5.zip |
LibWeb: Teach HtmlView how to render Markdown files :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/HtmlView.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibWeb/HtmlView.cpp b/Libraries/LibWeb/HtmlView.cpp index 5ed2bb7504..8c0fb19eae 100644 --- a/Libraries/LibWeb/HtmlView.cpp +++ b/Libraries/LibWeb/HtmlView.cpp @@ -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"; |