/* * Copyright (c) 2019-2020, Sergey Bugaev * Copyright (c) 2021, Peter Elliott * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace Markdown { DeprecatedString Document::render_to_html(StringView extra_head_contents) const { StringBuilder builder; builder.append(R"~~~( )~~~"sv); if (!extra_head_contents.is_empty()) builder.append(extra_head_contents); builder.append(R"~~~( )~~~"sv); builder.append(render_to_inline_html()); builder.append(R"~~~( )~~~"sv); return builder.to_deprecated_string(); } DeprecatedString Document::render_to_inline_html() const { return m_container->render_to_html(); } DeprecatedString Document::render_for_terminal(size_t view_width) const { StringBuilder builder; for (auto& line : m_container->render_lines_for_terminal(view_width)) { builder.append(line); builder.append("\n"sv); } return builder.to_deprecated_string(); } RecursionDecision Document::walk(Visitor& visitor) const { RecursionDecision rd = visitor.visit(*this); if (rd != RecursionDecision::Recurse) return rd; return m_container->walk(visitor); } OwnPtr Document::parse(StringView str) { Vector const lines_vec = str.lines(); LineIterator lines(lines_vec.begin()); return make(ContainerBlock::parse(lines)); } }