libcmd/markdown: avoid stripping ANSI escapes

Instead, we instruct lowdown not to emit them in the first place.

Fixes #622.

Change-Id: I596bb873943c2c0b5067c5357a90457f01307cfa
This commit is contained in:
Linus Heckemann
2025-03-10 19:32:00 +01:00
parent 93c3ca4e92
commit a954a5ea2f
2 changed files with 13 additions and 1 deletions
+9
View File
@@ -0,0 +1,9 @@
---
synopsis: "Fix `--help` formatting"
issues: [fj#622]
cls: [2776]
category: "Fixes"
credits: ["lheckemann"]
---
The help printed when invoking `nix` or `nix-store` and subcommands with `--help` previously contained garbled terminal escapes. These have been removed.
+4 -1
View File
@@ -21,6 +21,9 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
.feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES,
.oflags = LOWDOWN_TERM_NOLINK,
};
if (!shouldANSI()) {
opts.oflags |= LOWDOWN_TERM_NOANSI;
}
auto doc = lowdown_doc_new(&opts);
if (!doc)
@@ -47,7 +50,7 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
if (!rndr_res)
throw Error("allocation error while rendering Markdown");
return filterANSIEscapes(std::string(buf->data, buf->size), !shouldANSI());
return std::string(buf->data, buf->size);
}
}