LibGemini: Implement rendering text/gemini documents to HTML

This also sets Content-Type to whatever 'meta' contains on success, to
allow the browser to pick up what the document contains.
This commit is contained in:
AnotherTest 2020-05-16 15:38:13 +04:30 committed by Andreas Kling
parent a4902e0eec
commit 013cb76d77
Notes: sideshowbarker 2024-07-19 06:33:39 +09:00
8 changed files with 424 additions and 1 deletions

View file

@ -32,6 +32,7 @@
#include <LibGUI/Painter.h>
#include <LibGUI/ScrollBar.h>
#include <LibGUI/Window.h>
#include <LibGemini/Document.h>
#include <LibGfx/ImageDecoder.h>
#include <LibJS/Runtime/Value.h>
#include <LibMarkdown/Document.h>
@ -387,6 +388,13 @@ static RefPtr<Document> create_image_document(const ByteBuffer& data, const URL&
return document;
}
static RefPtr<Document> create_gemini_document(const ByteBuffer& data, const URL& url)
{
auto markdown_document = Gemini::Document::parse({ (const char*)data.data(), data.size() }, url);
return parse_html_document(markdown_document->render_to_html(), url);
}
String encoding_from_content_type(const String& content_type)
{
auto offset = content_type.index_of("charset=");
@ -426,6 +434,8 @@ static RefPtr<Document> create_document_from_mime_type(const ByteBuffer& data, c
return create_text_document(data, url);
if (mime_type == "text/markdown")
return create_markdown_document(data, url);
if (mime_type == "text/gemini")
return create_gemini_document(data, url);
if (mime_type == "text/html")
return parse_html_document(data, url, encoding);
return nullptr;