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:
parent
4284497d98
commit
da8759bb41
1 changed files with 10 additions and 2 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue