1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-24 06:22:07 +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 { namespace Markdown {
String Document::render_to_html() const String Document::render_to_html(StringView extra_head_contents) const
{ {
StringBuilder builder; StringBuilder builder;
builder.append(R"~~~(<!DOCTYPE html>
builder.append("<!DOCTYPE html>\n"sv); <html>
builder.append("<html>\n"sv); <head>
builder.append("<head>\n"sv); <style>
builder.append("<style>\n"sv); code { white-space: pre; }
builder.append("code { white-space: pre; }\n"sv); </style>
builder.append("</style>\n"sv); )~~~"sv);
builder.append("</head>\n"sv); if (!extra_head_contents.is_empty())
builder.append("<body>\n"sv); builder.append(extra_head_contents);
builder.append(R"~~~(
</head>
<body>
)~~~"sv);
builder.append(render_to_inline_html()); builder.append(render_to_inline_html());
builder.append("</body>\n"sv); builder.append(R"~~~(
builder.append("</html>\n"sv); </body>
</html>)~~~"sv);
return builder.build(); return builder.build();
} }

View file

@ -19,7 +19,7 @@ public:
: m_container(move(container)) : 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_to_inline_html() const;
String render_for_terminal(size_t view_width = 0) const; String render_for_terminal(size_t view_width = 0) const;