mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +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
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/CarwynNelson Commit: https://github.com/SerenityOS/serenity/commit/e44abaa777 Pull-request: https://github.com/SerenityOS/serenity/pull/19382 Reviewed-by: https://github.com/BenWiederhake ✅ Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/bugaevc ✅ Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/timschumi ✅
4 changed files with 14 additions and 8 deletions
|
@ -43,15 +43,15 @@ DeprecatedString Document::render_to_inline_html() const
|
|||
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;
|
||||
for (auto& line : m_container->render_lines_for_terminal(view_width)) {
|
||||
builder.append(line);
|
||||
builder.append("\n"sv);
|
||||
TRY(builder.try_append(line));
|
||||
TRY(builder.try_append("\n"sv));
|
||||
}
|
||||
|
||||
return builder.to_deprecated_string();
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
RecursionDecision Document::walk(Visitor& visitor) const
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibMarkdown/Block.h>
|
||||
#include <LibMarkdown/ContainerBlock.h>
|
||||
|
||||
|
@ -21,7 +22,7 @@ public:
|
|||
}
|
||||
DeprecatedString render_to_html(StringView extra_head_contents = ""sv) 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
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
|
@ -100,7 +101,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto document = Markdown::Document::parse(source);
|
||||
VERIFY(document);
|
||||
|
||||
DeprecatedString rendered = document->render_for_terminal(view_width);
|
||||
auto rendered = TRY(document->render_for_terminal(view_width));
|
||||
outln("{}", rendered);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
DeprecatedString res = html ? document->render_to_html() : document->render_for_terminal(view_width);
|
||||
out("{}", res);
|
||||
if (html) {
|
||||
out("{}", document->render_to_html());
|
||||
} else {
|
||||
out("{}", TRY(document->render_for_terminal(view_width)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue