mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
LibMarkdown: Make thematic break parsing more correct
also fix a conflict with lists and thematic breaks
This commit is contained in:
parent
5ad44ac2e5
commit
c15c57a6af
2 changed files with 6 additions and 10 deletions
|
@ -108,11 +108,11 @@ OwnPtr<ContainerBlock> ContainerBlock::parse(LineIterator& lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool any = try_parse_block<Table>(lines, blocks)
|
bool any = try_parse_block<Table>(lines, blocks)
|
||||||
|
|| try_parse_block<HorizontalRule>(lines, blocks)
|
||||||
|| try_parse_block<List>(lines, blocks)
|
|| try_parse_block<List>(lines, blocks)
|
||||||
|| try_parse_block<CodeBlock>(lines, blocks)
|
|| try_parse_block<CodeBlock>(lines, blocks)
|
||||||
|| try_parse_block<CommentBlock>(lines, blocks)
|
|| try_parse_block<CommentBlock>(lines, blocks)
|
||||||
|| try_parse_block<Heading>(lines, blocks)
|
|| try_parse_block<Heading>(lines, blocks)
|
||||||
|| try_parse_block<HorizontalRule>(lines, blocks)
|
|
||||||
|| try_parse_block<BlockQuote>(lines, blocks);
|
|| try_parse_block<BlockQuote>(lines, blocks);
|
||||||
|
|
||||||
if (any) {
|
if (any) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibMarkdown/HorizontalRule.h>
|
#include <LibMarkdown/HorizontalRule.h>
|
||||||
#include <LibMarkdown/Visitor.h>
|
#include <LibMarkdown/Visitor.h>
|
||||||
|
#include <LibRegex/Regex.h>
|
||||||
|
|
||||||
namespace Markdown {
|
namespace Markdown {
|
||||||
|
|
||||||
|
@ -34,6 +35,8 @@ RecursionDecision HorizontalRule::walk(Visitor& visitor) const
|
||||||
return RecursionDecision::Continue;
|
return RecursionDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Regex<ECMA262> thematic_break_re("^ {0,3}([\\*\\-_])(\\s*\\1\\s*){2,}$");
|
||||||
|
|
||||||
OwnPtr<HorizontalRule> HorizontalRule::parse(LineIterator& lines)
|
OwnPtr<HorizontalRule> HorizontalRule::parse(LineIterator& lines)
|
||||||
{
|
{
|
||||||
if (lines.is_end())
|
if (lines.is_end())
|
||||||
|
@ -41,16 +44,9 @@ OwnPtr<HorizontalRule> HorizontalRule::parse(LineIterator& lines)
|
||||||
|
|
||||||
StringView line = *lines;
|
StringView line = *lines;
|
||||||
|
|
||||||
if (line.length() < 3)
|
auto match = thematic_break_re.match(line);
|
||||||
|
if (!match.success)
|
||||||
return {};
|
return {};
|
||||||
if (!line.starts_with('-') && !line.starts_with('_') && !line.starts_with('*'))
|
|
||||||
return {};
|
|
||||||
|
|
||||||
auto first_character = line.characters_without_null_termination()[0];
|
|
||||||
for (auto ch : line) {
|
|
||||||
if (ch != first_character)
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
++lines;
|
++lines;
|
||||||
return make<HorizontalRule>();
|
return make<HorizontalRule>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue