summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibMarkdown
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
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')
-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>();
}