1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27: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

@ -26,6 +26,7 @@
#pragma once
#include <AK/OwnPtr.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibMarkdown/Block.h>
@ -35,15 +36,20 @@ namespace Markdown {
class Heading final : public Block {
public:
virtual ~Heading() override {}
Heading(Text&& text, size_t level)
: m_text(move(text))
, m_level(level)
{
}
virtual ~Heading() override { }
virtual String render_to_html() const override;
virtual String render_for_terminal() const override;
virtual bool parse(Vector<StringView>::ConstIterator& lines) override;
static OwnPtr<Heading> parse(Vector<StringView>::ConstIterator& lines);
private:
Text m_text;
int m_level { -1 };
size_t m_level { 0 };
};
}