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.
This commit is contained in:
Peter Elliott 2021-08-29 13:14:48 -07:00 committed by Andreas Kling
parent 83680934e5
commit 57ec19f963
Notes: sideshowbarker 2024-07-18 04:59:35 +09:00
2 changed files with 12 additions and 2 deletions

View File

@ -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();
}

View File

@ -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&);