summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Elliott <pelliott@ualberta.ca>2021-08-29 13:14:48 -0700
committerAndreas Kling <kling@serenityos.org>2021-08-31 16:53:51 +0200
commit57ec19f963868402571f6dfaaf8b2e71a47e0db7 (patch)
treebe3c57e80286d9b43ccefa6f4b77503c465f744e
parent83680934e5f04919551ca99645054c470b4bc062 (diff)
downloadserenity-57ec19f963868402571f6dfaaf8b2e71a47e0db7.zip
LibMarkdown: Add render_to_inline_html() to Document
This api is useful when you want to render a markdown document to HTML, but you want to embed it in a existing html document.
-rw-r--r--Userland/Libraries/LibMarkdown/Document.cpp13
-rw-r--r--Userland/Libraries/LibMarkdown/Document.h1
2 files changed, 12 insertions, 2 deletions
diff --git a/Userland/Libraries/LibMarkdown/Document.cpp b/Userland/Libraries/LibMarkdown/Document.cpp
index a0851f018d..dd68d9d17a 100644
--- a/Userland/Libraries/LibMarkdown/Document.cpp
+++ b/Userland/Libraries/LibMarkdown/Document.cpp
@@ -28,13 +28,22 @@ String Document::render_to_html() const
builder.append("</head>\n");
builder.append("<body>\n");
+ builder.append(render_to_inline_html());
+
+ builder.append("</body>\n");
+ builder.append("</html>\n");
+ return builder.build();
+}
+
+String Document::render_to_inline_html() const
+{
+ StringBuilder builder;
+
for (auto& block : m_blocks) {
auto s = block.render_to_html();
builder.append(s);
}
- builder.append("</body>\n");
- builder.append("</html>\n");
return builder.build();
}
diff --git a/Userland/Libraries/LibMarkdown/Document.h b/Userland/Libraries/LibMarkdown/Document.h
index 154fe7d802..2337fa4969 100644
--- a/Userland/Libraries/LibMarkdown/Document.h
+++ b/Userland/Libraries/LibMarkdown/Document.h
@@ -15,6 +15,7 @@ namespace Markdown {
class Document final {
public:
String render_to_html() const;
+ String render_to_inline_html() const;
String render_for_terminal(size_t view_width = 0) const;
static OwnPtr<Document> parse(const StringView&);