summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibMarkdown/ContainerBlock.cpp2
-rw-r--r--Userland/Libraries/LibMarkdown/HorizontalRule.cpp14
2 files changed, 6 insertions, 10 deletions
diff --git a/Userland/Libraries/LibMarkdown/ContainerBlock.cpp b/Userland/Libraries/LibMarkdown/ContainerBlock.cpp
index acb0f4db59..7d6223c09a 100644
--- a/Userland/Libraries/LibMarkdown/ContainerBlock.cpp
+++ b/Userland/Libraries/LibMarkdown/ContainerBlock.cpp
@@ -108,11 +108,11 @@ OwnPtr<ContainerBlock> ContainerBlock::parse(LineIterator& lines)
}
bool any = try_parse_block<Table>(lines, blocks)
+ || try_parse_block<HorizontalRule>(lines, blocks)
|| try_parse_block<List>(lines, blocks)
|| try_parse_block<CodeBlock>(lines, blocks)
|| try_parse_block<CommentBlock>(lines, blocks)
|| try_parse_block<Heading>(lines, blocks)
- || try_parse_block<HorizontalRule>(lines, blocks)
|| try_parse_block<BlockQuote>(lines, blocks);
if (any) {
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>();
}