1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 11:17:43 +00:00

LibMarkdown: Change internal MD API to return OwnPtrs

Previously, all Markdown blocks had a virtual parse method which has
been swapped out for a static parse method returning an OwnPtr of
that block's type.

The Text class also now has a static parse method that will return an
Optional<Text>.
This commit is contained in:
FalseHonesty 2020-05-18 16:58:00 -04:00 committed by Andreas Kling
parent 7ca562b200
commit 20faa93cb0
15 changed files with 110 additions and 64 deletions

View file

@ -67,19 +67,18 @@ String Document::render_for_terminal() const
template<typename BlockType>
static bool helper(Vector<StringView>::ConstIterator& lines, NonnullOwnPtrVector<Block>& blocks)
{
NonnullOwnPtr<BlockType> block = make<BlockType>();
bool success = block->parse(lines);
if (!success)
OwnPtr<BlockType> block = BlockType::parse(lines);
if (!block)
return false;
blocks.append(move(block));
blocks.append(block.release_nonnull());
return true;
}
RefPtr<Document> Document::parse(const StringView& str)
OwnPtr<Document> Document::parse(const StringView& str)
{
const Vector<StringView> lines_vec = str.lines();
auto lines = lines_vec.begin();
auto document = adopt(*new Document);
auto document = make<Document>();
auto& blocks = document->m_blocks;
while (true) {