mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +00:00
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:
parent
83680934e5
commit
57ec19f963
Notes:
sideshowbarker
2024-07-18 04:59:35 +09:00
Author: https://github.com/petelliott
Commit: 57ec19f963
Pull-request: https://github.com/SerenityOS/serenity/pull/9679
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 12 additions and 2 deletions
|
@ -28,13 +28,22 @@ String Document::render_to_html() const
|
||||||
builder.append("</head>\n");
|
builder.append("</head>\n");
|
||||||
builder.append("<body>\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) {
|
for (auto& block : m_blocks) {
|
||||||
auto s = block.render_to_html();
|
auto s = block.render_to_html();
|
||||||
builder.append(s);
|
builder.append(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append("</body>\n");
|
|
||||||
builder.append("</html>\n");
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Markdown {
|
||||||
class Document final {
|
class Document final {
|
||||||
public:
|
public:
|
||||||
String render_to_html() const;
|
String render_to_html() const;
|
||||||
|
String render_to_inline_html() const;
|
||||||
String render_for_terminal(size_t view_width = 0) const;
|
String render_for_terminal(size_t view_width = 0) const;
|
||||||
|
|
||||||
static OwnPtr<Document> parse(const StringView&);
|
static OwnPtr<Document> parse(const StringView&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue