1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +00:00

LibMarkdown: Implement "tightness" for lists

From the commonmark spec:
A list is loose if any of its constituent list items are separated by
blank lines, or if any of its constituent list items directly contain
two block-level elements with a blank line between them. Otherwise a
list is tight. (The difference in HTML output is that paragraphs in a
loose list are wrapped in <p> tags, while paragraphs in a tight list are
not.)
This commit is contained in:
Peter Elliott 2021-09-28 01:12:00 -06:00 committed by Ali Mohammad Pur
parent 5bb87c630c
commit 0a21c2bace
15 changed files with 75 additions and 28 deletions

View file

@ -16,20 +16,29 @@ namespace Markdown {
class ContainerBlock final : public Block {
public:
ContainerBlock(NonnullOwnPtrVector<Block> blocks)
ContainerBlock(NonnullOwnPtrVector<Block> blocks, bool has_blank_lines, bool has_trailing_blank_lines)
: m_blocks(move(blocks))
, m_has_blank_lines(has_blank_lines)
, m_has_trailing_blank_lines(has_trailing_blank_lines)
{
}
virtual ~ContainerBlock() override { }
virtual String render_to_html() const override;
virtual String render_to_html(bool tight = false) const override;
virtual String render_for_terminal(size_t view_width = 0) const override;
static OwnPtr<ContainerBlock> parse(LineIterator& lines);
bool has_blank_lines() const { return m_has_blank_lines; }
bool has_trailing_blank_lines() const { return m_has_trailing_blank_lines; }
NonnullOwnPtrVector<Block> const& blocks() const { return m_blocks; }
private:
NonnullOwnPtrVector<Block> m_blocks;
bool m_has_blank_lines;
bool m_has_trailing_blank_lines;
};
}