mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
LibMarkdown: Convert render_to_terminal to String
This commit converts render_to_terminal from DeprecatedString to return an ErrorOr<String>. This is to aid moving `man` away from DeprecatedString. I have opted not to convert render_to_html and render_to_inline_html for now to keep this commit as small as possible.
This commit is contained in:
parent
e247da507f
commit
e44abaa777
|
@ -43,15 +43,15 @@ DeprecatedString Document::render_to_inline_html() const
|
||||||
return m_container->render_to_html();
|
return m_container->render_to_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Document::render_for_terminal(size_t view_width) const
|
ErrorOr<String> Document::render_for_terminal(size_t view_width) const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (auto& line : m_container->render_lines_for_terminal(view_width)) {
|
for (auto& line : m_container->render_lines_for_terminal(view_width)) {
|
||||||
builder.append(line);
|
TRY(builder.try_append(line));
|
||||||
builder.append("\n"sv);
|
TRY(builder.try_append("\n"sv));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
RecursionDecision Document::walk(Visitor& visitor) const
|
RecursionDecision Document::walk(Visitor& visitor) const
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibMarkdown/Block.h>
|
#include <LibMarkdown/Block.h>
|
||||||
#include <LibMarkdown/ContainerBlock.h>
|
#include <LibMarkdown/ContainerBlock.h>
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ public:
|
||||||
}
|
}
|
||||||
DeprecatedString render_to_html(StringView extra_head_contents = ""sv) const;
|
DeprecatedString render_to_html(StringView extra_head_contents = ""sv) const;
|
||||||
DeprecatedString render_to_inline_html() const;
|
DeprecatedString render_to_inline_html() const;
|
||||||
DeprecatedString render_for_terminal(size_t view_width = 0) const;
|
ErrorOr<String> render_for_terminal(size_t view_width = 0) const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Walk recursively through the document tree. Returning `RecursionDecision::Recurse` from
|
* Walk recursively through the document tree. Returning `RecursionDecision::Recurse` from
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/Utf8View.h>
|
#include <AK/Utf8View.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
@ -100,7 +101,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto document = Markdown::Document::parse(source);
|
auto document = Markdown::Document::parse(source);
|
||||||
VERIFY(document);
|
VERIFY(document);
|
||||||
|
|
||||||
DeprecatedString rendered = document->render_for_terminal(view_width);
|
auto rendered = TRY(document->render_for_terminal(view_width));
|
||||||
outln("{}", rendered);
|
outln("{}", rendered);
|
||||||
|
|
||||||
// FIXME: Remove this wait, it shouldn't be necessary but Shell does not
|
// FIXME: Remove this wait, it shouldn't be necessary but Shell does not
|
||||||
|
|
|
@ -56,7 +56,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString res = html ? document->render_to_html() : document->render_for_terminal(view_width);
|
if (html) {
|
||||||
out("{}", res);
|
out("{}", document->render_to_html());
|
||||||
|
} else {
|
||||||
|
out("{}", TRY(document->render_for_terminal(view_width)));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue