1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

libcmd: Fix rendering of absolute URLs in markdown

lowdown >= 1.4.0 supports LOWDOWN_TERM_NORELLINK to render
absolute urls. This is useful, since we want to keep links to
web resources and such intact.
This commit is contained in:
Sergei Zimmerman 2025-08-17 20:31:34 +03:00
parent 4284497d98
commit da8759bb41
No known key found for this signature in database

View file

@ -37,9 +37,17 @@ static std::string doRenderMarkdownToTerminal(std::string_view markdown)
.vmargin = 0, .vmargin = 0,
# endif # endif
.feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES, .feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES,
.oflags = LOWDOWN_TERM_NOLINK, .oflags =
# if HAVE_LOWDOWN_1_4
LOWDOWN_TERM_NORELLINK // To render full links while skipping relative ones
# else
LOWDOWN_TERM_NOLINK
# endif
}; };
if (!isTTY())
opts.oflags |= LOWDOWN_TERM_NOANSI;
auto doc = lowdown_doc_new(&opts); auto doc = lowdown_doc_new(&opts);
if (!doc) if (!doc)
throw Error("cannot allocate Markdown document"); throw Error("cannot allocate Markdown document");
@ -65,7 +73,7 @@ static std::string doRenderMarkdownToTerminal(std::string_view markdown)
if (!rndr_res) if (!rndr_res)
throw Error("allocation error while rendering Markdown"); throw Error("allocation error while rendering Markdown");
return filterANSIEscapes(std::string(buf->data, buf->size), !isTTY()); return std::string(buf->data, buf->size);
} }
std::string renderMarkdownToTerminal(std::string_view markdown) std::string renderMarkdownToTerminal(std::string_view markdown)