BlockQuote.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringBuilder.h>
  7. #include <LibMarkdown/BlockQuote.h>
  8. #include <LibMarkdown/Visitor.h>
  9. namespace Markdown {
  10. String BlockQuote::render_to_html(bool) const
  11. {
  12. StringBuilder builder;
  13. builder.append("<blockquote>\n");
  14. builder.append(m_contents->render_to_html());
  15. builder.append("</blockquote>\n");
  16. return builder.build();
  17. }
  18. String BlockQuote::render_for_terminal(size_t view_width) const
  19. {
  20. // FIXME: Rewrite the whole terminal renderer to make blockquote rendering possible
  21. return m_contents->render_for_terminal(view_width);
  22. }
  23. RecursionDecision BlockQuote::walk(Visitor& visitor) const
  24. {
  25. RecursionDecision rd = visitor.visit(*this);
  26. if (rd != RecursionDecision::Recurse)
  27. return rd;
  28. return m_contents->walk(visitor);
  29. }
  30. OwnPtr<BlockQuote> BlockQuote::parse(LineIterator& lines)
  31. {
  32. lines.push_context(LineIterator::Context::block_quote());
  33. if (lines.is_end()) {
  34. lines.pop_context();
  35. return {};
  36. }
  37. auto contents = ContainerBlock::parse(lines);
  38. lines.pop_context();
  39. if (!contents)
  40. return {};
  41. return make<BlockQuote>(move(contents));
  42. }
  43. }