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

LibMarkdown: Implement hard and soft line breaks

Hard line breaks insert a <br /> when two spaces are at the end of a
line. soft line breaks are just regular newlines, but whitespace is now
stripped before and after them
This commit is contained in:
Peter Elliott 2021-09-10 00:45:45 -06:00 committed by Andreas Kling
parent af5a07399e
commit 9c0563cc10
3 changed files with 75 additions and 3 deletions

View file

@ -55,6 +55,13 @@ public:
virtual size_t terminal_length() const override;
};
class BreakNode : public Node {
public:
virtual void render_to_html(StringBuilder& builder) const override;
virtual void render_for_terminal(StringBuilder& builder) const override;
virtual size_t terminal_length() const override;
};
class TextNode : public Node {
public:
String text;
@ -128,6 +135,10 @@ private:
VERIFY(is_run);
return data.length();
}
bool is_space() const
{
return data[0] == ' ';
}
bool operator==(StringView const& str) const { return str == data; }
};
@ -137,6 +148,8 @@ private:
static bool can_close_for(Token const& opening, Token const& closing);
static NonnullOwnPtr<MultiNode> parse_sequence(Vector<Token>::ConstIterator& tokens, bool in_link);
static NonnullOwnPtr<Node> parse_break(Vector<Token>::ConstIterator& tokens);
static NonnullOwnPtr<Node> parse_newline(Vector<Token>::ConstIterator& tokens);
static NonnullOwnPtr<Node> parse_emph(Vector<Token>::ConstIterator& tokens, bool in_link);
static NonnullOwnPtr<Node> parse_code(Vector<Token>::ConstIterator& tokens);
static NonnullOwnPtr<Node> parse_link(Vector<Token>::ConstIterator& tokens);