renderMarkdownToTerminal: Add _NIX_TEST_RAW_MARKDOWN env var

For testing only.
This commit is contained in:
Robert Hensing 2024-07-23 16:54:04 +02:00
parent 2b4e3f04a4
commit 97b0114ab8

View file

@ -1,5 +1,6 @@
#include "markdown.hh" #include "markdown.hh"
#include "util.hh" #include "environment-variables.hh"
#include "error.hh"
#include "finally.hh" #include "finally.hh"
#include "terminal.hh" #include "terminal.hh"
@ -10,9 +11,9 @@
namespace nix { namespace nix {
std::string renderMarkdownToTerminal(std::string_view markdown)
{
#if HAVE_LOWDOWN #if HAVE_LOWDOWN
static std::string doRenderMarkdownToTerminal(std::string_view markdown)
{
int windowWidth = getWindowSize().second; int windowWidth = getWindowSize().second;
struct lowdown_opts opts struct lowdown_opts opts
@ -52,9 +53,21 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
throw Error("allocation error while rendering Markdown"); throw Error("allocation error while rendering Markdown");
return filterANSIEscapes(std::string(buf->data, buf->size), !isTTY()); return filterANSIEscapes(std::string(buf->data, buf->size), !isTTY());
#else
return std::string(markdown);
#endif
} }
std::string renderMarkdownToTerminal(std::string_view markdown)
{
if (auto e = getEnv("_NIX_TEST_RAW_MARKDOWN"); e && *e == "1")
return std::string(markdown);
else
return doRenderMarkdownToTerminal(markdown);
} }
#else
std::string renderMarkdownToTerminal(std::string_view markdown)
{
return std::string(markdown);
}
#endif
} // namespace nix