2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-09-21 00:46:18 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
#include <AK/ByteString.h>
|
2021-09-19 11:04:24 -06:00
|
|
|
#include <AK/OwnPtr.h>
|
2023-06-13 16:15:13 +01:00
|
|
|
#include <AK/String.h>
|
2020-04-28 21:04:25 +02:00
|
|
|
#include <LibMarkdown/Block.h>
|
2021-09-19 11:04:24 -06:00
|
|
|
#include <LibMarkdown/ContainerBlock.h>
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2020-04-28 21:04:25 +02:00
|
|
|
namespace Markdown {
|
|
|
|
|
|
2020-05-18 16:58:00 -04:00
|
|
|
class Document final {
|
2019-09-21 00:46:18 +03:00
|
|
|
public:
|
2021-09-19 11:04:24 -06:00
|
|
|
Document(OwnPtr<ContainerBlock> container)
|
|
|
|
|
: m_container(move(container))
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString render_to_html(StringView extra_head_contents = ""sv) const;
|
|
|
|
|
ByteString render_to_inline_html() const;
|
2023-06-13 16:15:13 +01:00
|
|
|
ErrorOr<String> render_for_terminal(size_t view_width = 0) const;
|
2019-09-21 00:46:18 +03:00
|
|
|
|
2021-09-10 21:36:29 +02:00
|
|
|
/*
|
|
|
|
|
* Walk recursively through the document tree. Returning `RecursionDecision::Recurse` from
|
|
|
|
|
* `Visitor::visit` proceeds with the next element of the pre-order walk, usually a child element.
|
|
|
|
|
* Returning `RecursionDecision::Continue` skips the subtree, and usually proceeds with the next
|
|
|
|
|
* sibling. Returning `RecursionDecision::Break` breaks the recursion, with no further calls to
|
|
|
|
|
* any of the `Visitor::visit` methods.
|
|
|
|
|
*
|
|
|
|
|
* Note that `walk()` will only return `RecursionDecision::Continue` or `RecursionDecision::Break`.
|
|
|
|
|
*/
|
|
|
|
|
RecursionDecision walk(Visitor&) const;
|
|
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
static OwnPtr<Document> parse(StringView);
|
2019-09-21 00:46:18 +03:00
|
|
|
|
|
|
|
|
private:
|
2021-09-19 11:04:24 -06:00
|
|
|
OwnPtr<ContainerBlock> m_container;
|
2019-09-21 00:46:18 +03:00
|
|
|
};
|
2020-04-28 21:04:25 +02:00
|
|
|
|
|
|
|
|
}
|