mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
accommodate inconsistent output from lowdown
the `term` output mode leaves inline HTML around verbatim, while `nroff` mode (used for `man` pages) does not. the correct solution would be to pre-render all output with a more benign tool so we have less liabilities in our own code, but this has to do for now.
This commit is contained in:
parent
8232711c9f
commit
e0e47c0a68
5 changed files with 25 additions and 17 deletions
|
@ -6,7 +6,7 @@ let
|
||||||
showStoreDocs = import ./generate-store-info.nix;
|
showStoreDocs = import ./generate-store-info.nix;
|
||||||
in
|
in
|
||||||
|
|
||||||
commandDump:
|
inlineHTML: commandDump:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ let
|
||||||
# store parameters should not be part of command documentation to begin
|
# store parameters should not be part of command documentation to begin
|
||||||
# with, but instead be rendered on separate pages.
|
# with, but instead be rendered on separate pages.
|
||||||
maybeStoreDocs = optionalString (details ? doc)
|
maybeStoreDocs = optionalString (details ? doc)
|
||||||
(replaceStrings [ "@stores@" ] [ (showStoreDocs commandInfo.stores) ] details.doc);
|
(replaceStrings [ "@stores@" ] [ (showStoreDocs inlineHTML commandInfo.stores) ] details.doc);
|
||||||
|
|
||||||
maybeOptions = let
|
maybeOptions = let
|
||||||
allVisibleOptions = filterAttrs
|
allVisibleOptions = filterAttrs
|
||||||
|
@ -84,14 +84,14 @@ let
|
||||||
in optionalString (allVisibleOptions != {}) ''
|
in optionalString (allVisibleOptions != {}) ''
|
||||||
# Options
|
# Options
|
||||||
|
|
||||||
${showOptions allVisibleOptions}
|
${showOptions inlineHTML allVisibleOptions}
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
|
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
showOptions = allOptions:
|
showOptions = inlineHTML: allOptions:
|
||||||
let
|
let
|
||||||
showCategory = cat: opts: ''
|
showCategory = cat: opts: ''
|
||||||
${optionalString (cat != "") "## ${cat}"}
|
${optionalString (cat != "") "## ${cat}"}
|
||||||
|
@ -100,17 +100,21 @@ let
|
||||||
'';
|
'';
|
||||||
showOption = name: option:
|
showOption = name: option:
|
||||||
let
|
let
|
||||||
|
result = trim ''
|
||||||
|
- ${item}
|
||||||
|
|
||||||
|
${option.description}
|
||||||
|
'';
|
||||||
|
item = if inlineHTML
|
||||||
|
then ''<span id="opt-${name}">[`--${name}`](#opt-${name})</span> ${shortName} ${labels}''
|
||||||
|
else "`--${name}` ${shortName} ${labels}";
|
||||||
shortName = optionalString
|
shortName = optionalString
|
||||||
(option ? shortName)
|
(option ? shortName)
|
||||||
("/ `-${option.shortName}`");
|
("/ `-${option.shortName}`");
|
||||||
labels = optionalString
|
labels = optionalString
|
||||||
(option ? labels)
|
(option ? labels)
|
||||||
(concatStringsSep " " (map (s: "*${s}*") option.labels));
|
(concatStringsSep " " (map (s: "*${s}*") option.labels));
|
||||||
in trim ''
|
in result;
|
||||||
- <span id="opt-${name}">[`--${name}`](#opt-${name})</span> ${shortName} ${labels}
|
|
||||||
|
|
||||||
${option.description}
|
|
||||||
'';
|
|
||||||
categories = mapAttrs
|
categories = mapAttrs
|
||||||
# Convert each group from a list of key-value pairs back to an attrset
|
# Convert each group from a list of key-value pairs back to an attrset
|
||||||
(_: listToAttrs)
|
(_: listToAttrs)
|
||||||
|
|
|
@ -3,18 +3,21 @@ let
|
||||||
inherit (import ./utils.nix) concatStrings indent optionalString squash;
|
inherit (import ./utils.nix) concatStrings indent optionalString squash;
|
||||||
in
|
in
|
||||||
|
|
||||||
prefix: settingsInfo:
|
# `inlineHTML` is a hack to accommodate inconsistent output from `lowdown`
|
||||||
|
{ prefix, inlineHTML ? true }: settingsInfo:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
showSetting = prefix: setting: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }:
|
showSetting = prefix: setting: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }:
|
||||||
let
|
let
|
||||||
result = squash ''
|
result = squash ''
|
||||||
- <span id="${prefix}-${setting}">[`${setting}`](#${prefix}-${setting})</span>
|
- ${item}
|
||||||
|
|
||||||
${indent " " body}
|
${indent " " body}
|
||||||
'';
|
'';
|
||||||
|
item = if inlineHTML
|
||||||
|
then ''<span id="${prefix}-${setting}">[`${setting}`](#${prefix}-${setting})</span>''
|
||||||
|
else "`${setting}`";
|
||||||
# separate body to cleanly handle indentation
|
# separate body to cleanly handle indentation
|
||||||
body = ''
|
body = ''
|
||||||
${description}
|
${description}
|
||||||
|
|
|
@ -4,7 +4,7 @@ let
|
||||||
showSettings = import ./generate-settings.nix;
|
showSettings = import ./generate-settings.nix;
|
||||||
in
|
in
|
||||||
|
|
||||||
storesInfo:
|
inlineHTML: storesInfo:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ let
|
||||||
|
|
||||||
### Settings
|
### Settings
|
||||||
|
|
||||||
${showSettings "store-${slug}" settings}
|
${showSettings { prefix = "store-${slug}"; inherit inlineHTML; } settings}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# markdown doesn't like spaces in URLs
|
# markdown doesn't like spaces in URLs
|
||||||
|
|
|
@ -98,12 +98,12 @@ $(d)/src/SUMMARY.md: $(d)/src/SUMMARY.md.in $(d)/src/command-ref/new-cli $(d)/sr
|
||||||
|
|
||||||
$(d)/src/command-ref/new-cli: $(d)/nix.json $(d)/utils.nix $(d)/generate-manpage.nix $(d)/generate-settings.nix $(d)/generate-store-info.nix $(bindir)/nix
|
$(d)/src/command-ref/new-cli: $(d)/nix.json $(d)/utils.nix $(d)/generate-manpage.nix $(d)/generate-settings.nix $(d)/generate-store-info.nix $(bindir)/nix
|
||||||
@rm -rf $@ $@.tmp
|
@rm -rf $@ $@.tmp
|
||||||
$(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix (builtins.readFile $<)'
|
$(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix true (builtins.readFile $<)'
|
||||||
@mv $@.tmp $@
|
@mv $@.tmp $@
|
||||||
|
|
||||||
$(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/utils.nix $(d)/generate-settings.nix $(d)/src/command-ref/conf-file-prefix.md $(d)/src/command-ref/experimental-features-shortlist.md $(bindir)/nix
|
$(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/utils.nix $(d)/generate-settings.nix $(d)/src/command-ref/conf-file-prefix.md $(d)/src/command-ref/experimental-features-shortlist.md $(bindir)/nix
|
||||||
@cat doc/manual/src/command-ref/conf-file-prefix.md > $@.tmp
|
@cat doc/manual/src/command-ref/conf-file-prefix.md > $@.tmp
|
||||||
$(trace-gen) $(nix-eval) --expr 'import doc/manual/generate-settings.nix "opt-" (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp;
|
$(trace-gen) $(nix-eval) --expr 'import doc/manual/generate-settings.nix { prefix = "opt-"; } (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp;
|
||||||
@mv $@.tmp $@
|
@mv $@.tmp $@
|
||||||
|
|
||||||
$(d)/nix.json: $(bindir)/nix
|
$(d)/nix.json: $(bindir)/nix
|
||||||
|
|
|
@ -234,7 +234,8 @@ static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel)
|
||||||
vDump->mkString(toplevel.dumpCli());
|
vDump->mkString(toplevel.dumpCli());
|
||||||
|
|
||||||
auto vRes = state.allocValue();
|
auto vRes = state.allocValue();
|
||||||
state.callFunction(*vGenerateManpage, *vDump, *vRes, noPos);
|
state.callFunction(*vGenerateManpage, state.getBuiltin("false"), *vRes, noPos);
|
||||||
|
state.callFunction(*vRes, *vDump, *vRes, noPos);
|
||||||
|
|
||||||
auto attr = vRes->attrs->get(state.symbols.create(mdName + ".md"));
|
auto attr = vRes->attrs->get(state.symbols.create(mdName + ".md"));
|
||||||
if (!attr)
|
if (!attr)
|
||||||
|
|
Loading…
Reference in a new issue