#include #include #include #include #include #include String MDDocument::render_to_html() const { StringBuilder builder; builder.append("\n"); builder.append("\n"); builder.append("\n"); builder.append("\n"); for (auto& block : m_blocks) { auto s = block.render_to_html(); builder.append(s); } builder.append("\n"); builder.append("\n"); return builder.build(); } String MDDocument::render_for_terminal() const { StringBuilder builder; for (auto& block : m_blocks) { auto s = block.render_for_terminal(); builder.append(s); } return builder.build(); } template static bool helper(Vector::ConstIterator& lines, NonnullOwnPtrVector& blocks) { NonnullOwnPtr block = make(); bool success = block->parse(lines); if (!success) return false; blocks.append(move(block)); return true; } bool MDDocument::parse(const StringView& str) { const Vector lines_vec = str.lines(); auto lines = lines_vec.begin(); while (true) { if (lines.is_end()) return true; if ((*lines).is_empty()) { ++lines; continue; } bool any = helper(lines, m_blocks) || helper(lines, m_blocks) || helper(lines, m_blocks) || helper(lines, m_blocks); if (!any) return false; } }