Skip to content

Commit

Permalink
Make lowdown optional
Browse files Browse the repository at this point in the history
Co-authored-by: John Ericson <[email protected]>
  • Loading branch information
wegank and Ericson2314 committed Jan 8, 2024
1 parent 8e865f3 commit bbd0a95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,21 @@ PKG_CHECK_MODULES([NLOHMANN_JSON], [nlohmann_json >= 3.9])
# 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.
Expand Down
5 changes: 5 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
# Whether to build the regular manual
, 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
# not-yet-released version of Nix in the manul, from the individual
# change log entries in the directory.
Expand Down Expand Up @@ -213,6 +216,7 @@ in {
xz
] ++ lib.optionals (!stdenv.hostPlatform.isWindows) [
editline
] ++ lib.optionals enableMarkdown [
lowdown
] ++ lib.optionals buildUnitTests [
gtest
Expand Down Expand Up @@ -269,6 +273,7 @@ in {
(lib.enableFeature doInstallCheck "functional-tests")
(lib.enableFeature enableInternalAPIDocs "internal-api-docs")
(lib.enableFeature enableManual "doc-gen")
(lib.enableFeature enableMarkdown "markdown")
(lib.enableFeature installUnitTests "install-unit-tests")
] ++ lib.optionals (!forDevShell) [
"--sysconfdir=/etc"
Expand Down
6 changes: 6 additions & 0 deletions src/libcmd/markdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
#include "terminal.hh"

#include <sys/queue.h>
#if HAVE_LOWDOWN
#include <lowdown.h>
#endif

namespace nix {

std::string renderMarkdownToTerminal(std::string_view markdown)
{
#if HAVE_LOWDOWN
int windowWidth = getWindowSize().second;

struct lowdown_opts opts {
Expand Down Expand Up @@ -48,6 +51,9 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
throw Error("allocation error while rendering Markdown");

return filterANSIEscapes(std::string(buf->data, buf->size), !shouldANSI());
#else
return std::string(markdown);
#endif
}

}

0 comments on commit bbd0a95

Please sign in to comment.