mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 13:15:08 +00:00

This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
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_deprecated_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>();
|
|
}
|
|
|
|
}
|