lib.literalCode: init

This commit is contained in:
Luke Bailey
2025-12-21 15:18:17 +00:00
parent 4d2e351d55
commit 56cee4ffd3
+43
View File
@@ -707,6 +707,49 @@ rec {
inherit text;
};
/**
For use in the `defaultText` and `example` option attributes. Causes the
given string to be rendered verbatim in the documentation as a code
block with the language bassed on the provided input tag.
If you wish to render Nix code, please see `literalExpression`.
# Examples
:::{.example}
## `literalCode` usage example
```nix
myPythonScript = mkOption {
type = types.str;
description = ''
Example python script used by a module
'';
example = literalCode "python" ''
print("Hello world!")
'';
};
```
:::
# Inputs
`languageTag`
: The language tag to use when producing the code block (i.e. `js`, `rs`, etc).
`text`
: The text to render as a Nix expression
*/
literalCode =
languageTag: text:
lib.literalMD ''
```${languageTag}
${text}
```
'';
/**
For use in the `defaultText` and `example` option attributes. Causes the
given MD text to be inserted verbatim in the documentation, for when