mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +00:00

We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/DeprecatedString.h>
|
|
#include <AK/StringBuilder.h>
|
|
#include <LibMarkdown/HorizontalRule.h>
|
|
#include <LibMarkdown/Visitor.h>
|
|
#include <LibRegex/Regex.h>
|
|
|
|
namespace Markdown {
|
|
|
|
DeprecatedString HorizontalRule::render_to_html(bool) const
|
|
{
|
|
return "<hr />\n";
|
|
}
|
|
|
|
DeprecatedString HorizontalRule::render_for_terminal(size_t view_width) const
|
|
{
|
|
StringBuilder builder(view_width + 1);
|
|
for (size_t i = 0; i < view_width; ++i)
|
|
builder.append('-');
|
|
builder.append("\n\n"sv);
|
|
return builder.to_string();
|
|
}
|
|
|
|
RecursionDecision HorizontalRule::walk(Visitor& visitor) const
|
|
{
|
|
RecursionDecision rd = visitor.visit(*this);
|
|
if (rd != RecursionDecision::Recurse)
|
|
return rd;
|
|
// Normalize return value.
|
|
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())
|
|
return {};
|
|
|
|
StringView line = *lines;
|
|
|
|
auto match = thematic_break_re.match(line);
|
|
if (!match.success)
|
|
return {};
|
|
|
|
++lines;
|
|
return make<HorizontalRule>();
|
|
}
|
|
|
|
}
|