diff options
| author | Luke Bailey <baileylu@tcd.ie> | 2025-12-07 15:43:18 +0000 |
|---|---|---|
| committer | Luke Bailey <baileylu@tcd.ie> | 2025-12-21 15:18:17 +0000 |
| commit | 56cee4ffd37062d7598c36d064287ba86b2facd1 (patch) | |
| tree | e396934d37b250414f7ffb0207e38be21151914e /lib | |
| parent | lib.literalExpression: add example and properly describe function arg (diff) | |
| download | nixpkgs-56cee4ffd37062d7598c36d064287ba86b2facd1.tar.gz | |
lib.literalCode: init
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/options.nix | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/options.nix b/lib/options.nix index 42f451bd8674..e6b51fb0603e 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -709,6 +709,49 @@ rec { /** 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 a `literalExpression` would be too hard to read. |
