mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 09:06:15 +02:00
Merge pull request #9710 from wegank/disable-lowdown
Make lowdown optional
This commit is contained in:
commit
fa2a27d720
3 changed files with 26 additions and 1 deletions
16
configure.ac
16
configure.ac
|
@ -374,7 +374,21 @@ PKG_CHECK_MODULES([NLOHMANN_JSON], [nlohmann_json >= 3.9])
|
||||||
|
|
||||||
|
|
||||||
# Look for lowdown library.
|
# Look for lowdown library.
|
||||||
PKG_CHECK_MODULES([LOWDOWN], [lowdown >= 0.9.0], [CXXFLAGS="$LOWDOWN_CFLAGS $CXXFLAGS"])
|
AC_ARG_ENABLE([markdown], AS_HELP_STRING([--enable-markdown], [Enable Markdown rendering in the Nix binary (requires lowdown) [default=auto]]),
|
||||||
|
enable_markdown=$enableval, enable_markdown=auto)
|
||||||
|
AS_CASE(["$enable_markdown"],
|
||||||
|
[yes | auto], [
|
||||||
|
PKG_CHECK_MODULES([LOWDOWN], [lowdown >= 0.9.0], [
|
||||||
|
CXXFLAGS="$LOWDOWN_CFLAGS $CXXFLAGS"
|
||||||
|
have_lowdown=1
|
||||||
|
AC_DEFINE(HAVE_LOWDOWN, 1, [Whether lowdown is available and should be used for Markdown rendering.])
|
||||||
|
], [
|
||||||
|
AS_IF([test "x$enable_markdown" == "xyes"], [AC_MSG_ERROR([--enable-markdown was specified, but lowdown was not found.])])
|
||||||
|
])
|
||||||
|
],
|
||||||
|
[no], [have_lowdown=],
|
||||||
|
[AC_MSG_ERROR([--enable-markdown must be one of: yes, no, auto])])
|
||||||
|
AC_SUBST(HAVE_LOWDOWN, [$have_lowdown])
|
||||||
|
|
||||||
|
|
||||||
# Look for libgit2.
|
# Look for libgit2.
|
||||||
|
|
|
@ -68,6 +68,9 @@
|
||||||
# Whether to build the regular manual
|
# Whether to build the regular manual
|
||||||
, enableManual ? __forDefaults.canRunInstalled
|
, enableManual ? __forDefaults.canRunInstalled
|
||||||
|
|
||||||
|
# Whether to enable Markdown rendering in the Nix binary.
|
||||||
|
, enableMarkdown ? !stdenv.hostPlatform.isWindows
|
||||||
|
|
||||||
# Whether to compile `rl-next.md`, the release notes for the next
|
# Whether to compile `rl-next.md`, the release notes for the next
|
||||||
# not-yet-released version of Nix in the manul, from the individual
|
# not-yet-released version of Nix in the manul, from the individual
|
||||||
# change log entries in the directory.
|
# change log entries in the directory.
|
||||||
|
@ -213,6 +216,7 @@ in {
|
||||||
xz
|
xz
|
||||||
] ++ lib.optionals (!stdenv.hostPlatform.isWindows) [
|
] ++ lib.optionals (!stdenv.hostPlatform.isWindows) [
|
||||||
editline
|
editline
|
||||||
|
] ++ lib.optionals enableMarkdown [
|
||||||
lowdown
|
lowdown
|
||||||
] ++ lib.optionals buildUnitTests [
|
] ++ lib.optionals buildUnitTests [
|
||||||
gtest
|
gtest
|
||||||
|
@ -269,6 +273,7 @@ in {
|
||||||
(lib.enableFeature doInstallCheck "functional-tests")
|
(lib.enableFeature doInstallCheck "functional-tests")
|
||||||
(lib.enableFeature enableInternalAPIDocs "internal-api-docs")
|
(lib.enableFeature enableInternalAPIDocs "internal-api-docs")
|
||||||
(lib.enableFeature enableManual "doc-gen")
|
(lib.enableFeature enableManual "doc-gen")
|
||||||
|
(lib.enableFeature enableMarkdown "markdown")
|
||||||
(lib.enableFeature installUnitTests "install-unit-tests")
|
(lib.enableFeature installUnitTests "install-unit-tests")
|
||||||
] ++ lib.optionals (!forDevShell) [
|
] ++ lib.optionals (!forDevShell) [
|
||||||
"--sysconfdir=/etc"
|
"--sysconfdir=/etc"
|
||||||
|
|
|
@ -4,12 +4,15 @@
|
||||||
#include "terminal.hh"
|
#include "terminal.hh"
|
||||||
|
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
#if HAVE_LOWDOWN
|
||||||
#include <lowdown.h>
|
#include <lowdown.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
std::string renderMarkdownToTerminal(std::string_view markdown)
|
std::string renderMarkdownToTerminal(std::string_view markdown)
|
||||||
{
|
{
|
||||||
|
#if HAVE_LOWDOWN
|
||||||
int windowWidth = getWindowSize().second;
|
int windowWidth = getWindowSize().second;
|
||||||
|
|
||||||
struct lowdown_opts opts {
|
struct lowdown_opts opts {
|
||||||
|
@ -48,6 +51,9 @@ 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), !shouldANSI());
|
return filterANSIEscapes(std::string(buf->data, buf->size), !shouldANSI());
|
||||||
|
#else
|
||||||
|
return std::string(markdown);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue