From 90311e2493118c53e6e4b2a8d5a786b929ae44e4 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 8 Dec 2022 09:08:15 +0100 Subject: doc-options-md: support literalMD / mdDoc also format --- doc-options-md.nix | 77 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 33 deletions(-) (limited to 'doc-options-md.nix') diff --git a/doc-options-md.nix b/doc-options-md.nix index 5cbc7c2..1cc1bf2 100644 --- a/doc-options-md.nix +++ b/doc-options-md.nix @@ -1,55 +1,66 @@ -{ outputAttrPath, optionsAttrPath, optionsInternal ? true, }: - -{ lib, options, pkgs, ... }: - -with lib; - -let +{ + outputAttrPath, + optionsAttrPath, + optionsInternal ? true, +}: { + lib, + options, + pkgs, + ... +}: +with lib; let visibleOptionDocs = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options); isLiteral = value: - value ? _type && - (value._type == "literalExpression" || value._type == "literalExample"); + value + ? _type + && (value._type == "literalExpression" + || value._type == "literalExample" + || value._type == "literalMD"); toValue = value: - if isLiteral value then value.text - else generators.toPretty { } value; + if isLiteral value + then value.text + else generators.toPretty {} value; + + toText = value: + if value ? _type + then value.text + else value; - toMarkdown = option: - '' - ## `${option.name}` + toMarkdown = option: '' + ## `${option.name}` - ${option.description} + ${toText option.description} - ${optionalString (option ? default) '' - **Default value**: + ${optionalString (option ? default) '' + **Default value**: - ```nix - ${toValue option.default} - ``` - ''} + ```nix + ${toValue option.default} + ``` + ''} - **Type**: ${option.type}${optionalString option.readOnly " (read only)"} + **Type**: ${option.type}${optionalString option.readOnly " (read only)"} - ${optionalString (option ? example) '' - **Example**: + ${optionalString (option ? example) '' + **Example**: - ```nix - ${toValue option.example} - ``` - ''} + ```nix + ${toValue option.example} + ``` + ''} - Declared in: + Declared in: - ${concatStringsSep "\n" (map (decl: "- ${decl}") option.declarations)} + ${concatStringsSep "\n" (map (decl: "- ${decl}") option.declarations)} - ''; + ''; # TODO: rewrite "Declared in" so that it points to GitHub repository options-md = concatStringsSep "\n" (map toMarkdown visibleOptionDocs); -in -{ +in { config = setAttrByPath outputAttrPath { doc-options-md = pkgs.writeText "options.md" options-md; }; -- cgit v1.2.3