1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

LibMarkdown: Allow extra content to be inserted into HTML output's head

This lets users supply custom styling and scripting, among other things.
This commit is contained in:
Sam Atkins 2022-09-27 11:35:10 +01:00 committed by Linus Groh
parent 1da53ef854
commit aea4fbdd7b
2 changed files with 19 additions and 13 deletions

View file

@ -12,23 +12,29 @@
namespace Markdown {
String Document::render_to_html() const
String Document::render_to_html(StringView extra_head_contents) const
{
StringBuilder builder;
builder.append("<!DOCTYPE html>\n"sv);
builder.append("<html>\n"sv);
builder.append("<head>\n"sv);
builder.append("<style>\n"sv);
builder.append("code { white-space: pre; }\n"sv);
builder.append("</style>\n"sv);
builder.append("</head>\n"sv);
builder.append("<body>\n"sv);
builder.append(R"~~~(<!DOCTYPE html>
<html>
<head>
<style>
code { white-space: pre; }
</style>
)~~~"sv);
if (!extra_head_contents.is_empty())
builder.append(extra_head_contents);
builder.append(R"~~~(
</head>
<body>
)~~~"sv);
builder.append(render_to_inline_html());
builder.append("</body>\n"sv);
builder.append("</html>\n"sv);
builder.append(R"~~~(
</body>
</html>)~~~"sv);
return builder.build();
}

View file

@ -19,7 +19,7 @@ public:
: m_container(move(container))
{
}
String render_to_html() const;
String render_to_html(StringView extra_head_contents = ""sv) const;
String render_to_inline_html() const;
String render_for_terminal(size_t view_width = 0) const;