ladybird/Userland/Libraries/LibMarkdown/Document.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
* Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
2019-09-21 00:46:18 +03:00
#include <AK/StringBuilder.h>
#include <LibMarkdown/Document.h>
#include <LibMarkdown/LineIterator.h>
2019-09-21 00:46:18 +03:00
namespace Markdown {
String Document::render_to_html() const
2019-09-21 00:46:18 +03:00
{
StringBuilder builder;
builder.append("<!DOCTYPE html>\n");
builder.append("<html>\n");
builder.append("<head>\n");
builder.append("<style>\n");
builder.append("code { white-space: pre; }\n");
builder.append("</style>\n");
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
{
return m_container->render_to_html();
2019-09-21 00:46:18 +03:00
}
String Document::render_for_terminal(size_t view_width) const
2019-09-21 00:46:18 +03:00
{
return m_container->render_for_terminal(view_width);
2019-09-21 00:46:18 +03:00
}
OwnPtr<Document> Document::parse(const StringView& str)
2019-09-21 00:46:18 +03:00
{
const Vector<StringView> lines_vec = str.lines();
LineIterator lines(lines_vec.begin());
return make<Document>(ContainerBlock::parse(lines));
2019-09-21 00:46:18 +03:00
}
}