diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-08-24 18:10:33 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-08-24 18:10:33 +0200 |
commit | d0690bc311ee4969fc35604fed0fe819d4938704 (patch) | |
tree | 647187fb8f275f9a4db5d9edd99c742cda147da7 /src/nix/repl.cc | |
parent | 0f314f3c2594e80322c675b70a61dcfda11bf423 (diff) |
nix repl ':doc': Render using lowdown
Diffstat (limited to 'src/nix/repl.cc')
-rw-r--r-- | src/nix/repl.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc index d370ca767..c7f8af742 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -32,6 +32,7 @@ extern "C" { #include "globals.hh" #include "command.hh" #include "finally.hh" +#include "markdown.hh" #if HAVE_BOEHMGC #define GC_INCLUDE_NEW @@ -518,10 +519,16 @@ bool NixRepl::processLine(string line) while (v2->type == tPrimOpApp) v2 = v2->primOpApp.left; if (v2->primOp->doc) { - // FIXME: format markdown. - if (!v2->primOp->args.empty()) - std::cout << fmt("Arguments: %s\n\n", concatStringsSep(" ", v2->primOp->args)); - std::cout << trim(stripIndentation(v2->primOp->doc)) << "\n"; + auto args = v2->primOp->args; + for (auto & arg : args) + arg = "*" + arg + "*"; + + auto markdown = + "**Synopsis:** `builtins." + (std::string) v2->primOp->name + "` " + + concatStringsSep(" ", args) + "\n\n" + + trim(stripIndentation(v2->primOp->doc)); + + std::cout << renderMarkdownToTerminal(markdown); } else throw Error("builtin function '%s' does not have documentation", v2->primOp->name); } else |