mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib/utils: add literalLua
for use in option docs
Creates a `literalExpression` equivalent to using `lib.nixvim.mkRaw`.
This commit is contained in:
parent
de99f2938f
commit
eb76e62a9b
3 changed files with 45 additions and 0 deletions
|
@ -124,6 +124,37 @@ rec {
|
|||
else
|
||||
throw "mkRaw: invalid input: ${lib.generators.toPretty { multiline = false; } r}";
|
||||
|
||||
/**
|
||||
Convert the given string into a literalExpression mkRaw.
|
||||
|
||||
For use in option documentation, such as examples and defaults.
|
||||
|
||||
# Example
|
||||
|
||||
```nix
|
||||
literalLua "print('hi')"
|
||||
=> literalExpression ''lib.nixvim.mkRaw "print('hi')"''
|
||||
=> {
|
||||
_type = "literalExpression";
|
||||
text = ''lib.nixvim.mkRaw "print('hi')"'';
|
||||
}
|
||||
```
|
||||
|
||||
# Type
|
||||
```
|
||||
literalLua :: String -> AttrSet
|
||||
```
|
||||
*/
|
||||
literalLua =
|
||||
r:
|
||||
let
|
||||
# Pass the value through mkRaw for validation
|
||||
raw = mkRaw r;
|
||||
# TODO: consider switching to lib.generators.mkLuaInline ?
|
||||
exp = "lib.nixvim.mkRaw " + builtins.toJSON raw.__raw;
|
||||
in
|
||||
lib.literalExpression exp;
|
||||
|
||||
wrapDo = string: ''
|
||||
do
|
||||
${string}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue