summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibMarkdown/HorizontalRule.cpp
diff options
context:
space:
mode:
authorPeter Elliott <pelliott@ualberta.ca>2022-04-24 22:44:53 -0600
committerAndreas Kling <kling@serenityos.org>2022-04-26 15:02:26 +0200
commitc15c57a6af582e8d8433bc1b293b471743fe2dc0 (patch)
tree148ee7166081f325375bbf0509712a19d1e1f2df /Userland/Libraries/LibMarkdown/HorizontalRule.cpp
parent5ad44ac2e5c40e7a7a8a724de4b983a2149d678c (diff)
downloadserenity-c15c57a6af582e8d8433bc1b293b471743fe2dc0.zip
LibMarkdown: Make thematic break parsing more correct
also fix a conflict with lists and thematic breaks
Diffstat (limited to 'Userland/Libraries/LibMarkdown/HorizontalRule.cpp')
-rw-r--r--Userland/Libraries/LibMarkdown/HorizontalRule.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/Userland/Libraries/LibMarkdown/HorizontalRule.cpp b/Userland/Libraries/LibMarkdown/HorizontalRule.cpp
index d18a9a489a..7bb8edb42f 100644
--- a/Userland/Libraries/LibMarkdown/HorizontalRule.cpp
+++ b/Userland/Libraries/LibMarkdown/HorizontalRule.cpp
@@ -8,6 +8,7 @@
#include <AK/StringBuilder.h>
#include <LibMarkdown/HorizontalRule.h>
#include <LibMarkdown/Visitor.h>
+#include <LibRegex/Regex.h>
namespace Markdown {
@@ -34,6 +35,8 @@ RecursionDecision HorizontalRule::walk(Visitor& visitor) const
return RecursionDecision::Continue;
}
+static Regex<ECMA262> thematic_break_re("^ {0,3}([\\*\\-_])(\\s*\\1\\s*){2,}$");
+
OwnPtr<HorizontalRule> HorizontalRule::parse(LineIterator& lines)
{
if (lines.is_end())
@@ -41,17 +44,10 @@ OwnPtr<HorizontalRule> HorizontalRule::parse(LineIterator& lines)
StringView line = *lines;
- if (line.length() < 3)
- return {};
- if (!line.starts_with('-') && !line.starts_with('_') && !line.starts_with('*'))
+ auto match = thematic_break_re.match(line);
+ if (!match.success)
return {};
- auto first_character = line.characters_without_null_termination()[0];
- for (auto ch : line) {
- if (ch != first_character)
- return {};
- }
-
++lines;
return make<HorizontalRule>();
}