/* * Copyright (c) 2021, Ben Wiederhake * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace Markdown { String CommentBlock::render_to_html(bool) const { StringBuilder builder; builder.append("\n"); return builder.build(); } String CommentBlock::render_for_terminal(size_t) const { return ""; } RecursionDecision CommentBlock::walk(Visitor& visitor) const { RecursionDecision rd = visitor.visit(*this); if (rd != RecursionDecision::Recurse) return rd; // Normalize return value. return RecursionDecision::Continue; } OwnPtr CommentBlock::parse(LineIterator& lines) { if (lines.is_end()) return {}; constexpr auto comment_start = ""sv; StringView line = *lines; if (!line.starts_with(comment_start)) return {}; line = line.substring_view(comment_start.length()); StringBuilder builder; while (true) { // Invariant: At the beginning of the loop, `line` is valid and should be added the the builder. bool ends_here = line.ends_with(comment_end); if (ends_here) line = line.substring_view(0, line.length() - comment_end.length()); builder.append(line); if (!ends_here) builder.append('\n'); ++lines; if (lines.is_end() || ends_here) { break; } line = *lines; } return make(builder.build()); } }