mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibMarkdown: Parse paragraphs line-wise
This gets rid of the doubled-up checks in `Paragraph::parse()`, and makes a paragraph the last possible kind of block to be parsed.
This commit is contained in:
parent
176a2f193c
commit
eef794b8c6
3 changed files with 61 additions and 50 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullOwnPtrVector.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibMarkdown/Block.h>
|
||||
#include <LibMarkdown/Text.h>
|
||||
|
@ -34,18 +35,34 @@ namespace Markdown {
|
|||
|
||||
class Paragraph final : public Block {
|
||||
public:
|
||||
explicit Paragraph(Text&& text)
|
||||
: m_text(move(text))
|
||||
class Line {
|
||||
public:
|
||||
explicit Line(Text&& text)
|
||||
: m_text(move(text))
|
||||
{
|
||||
}
|
||||
|
||||
static OwnPtr<Line> parse(Vector<StringView>::ConstIterator& lines);
|
||||
const Text& text() const { return m_text; }
|
||||
|
||||
private:
|
||||
Text m_text;
|
||||
};
|
||||
|
||||
Paragraph(NonnullOwnPtrVector<Line>&& lines)
|
||||
: m_lines(move(lines))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Paragraph() override { }
|
||||
|
||||
virtual String render_to_html() const override;
|
||||
virtual String render_for_terminal(size_t view_width = 0) const override;
|
||||
static OwnPtr<Paragraph> parse(Vector<StringView>::ConstIterator& lines);
|
||||
|
||||
void add_line(NonnullOwnPtr<Line>&& line);
|
||||
|
||||
private:
|
||||
Text m_text;
|
||||
NonnullOwnPtrVector<Line> m_lines;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue