-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathmdformat.nix
98 lines (93 loc) · 1.82 KB
/
mdformat.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
config,
lib,
mkFormatterModule,
...
}:
let
cfg = config.programs.mdformat;
in
{
meta.maintainers = [ "sebaszv" ];
imports = [
(mkFormatterModule {
name = "mdformat";
package = [
"python3Packages"
"mdformat"
];
includes = [ "*.md" ];
})
];
/*
The options and descriptions were taken from the mdformat README
on the project's GitHub page:
<https://github.com/hukkin/mdformat>
*/
options.programs.mdformat.settings =
let
inherit (lib.types)
bool
enum
int
nullOr
oneOf
;
in
{
end-of-line = lib.mkOption {
description = ''
Output file line ending mode.
'';
type = nullOr (enum [
"crlf"
"lf"
"keep"
]);
example = "lf";
default = null;
};
number = lib.mkOption {
description = ''
Apply consecutive numbering to ordered lists.
'';
type = bool;
example = false;
default = false;
};
wrap = lib.mkOption {
description = ''
Paragraph word wrap mode.
Set to an INTEGER to wrap at that length.
'';
type = nullOr (oneOf [
int
(enum [
"keep"
"no"
])
]);
example = "keep";
default = null;
};
};
config = lib.mkIf cfg.enable {
settings.formatter.mdformat.options =
let
inherit (cfg.settings)
end-of-line
number
wrap
;
in
(lib.optionals (end-of-line != null) [
"--end-of-line"
end-of-line
])
++ (lib.optional number "--number")
++ (lib.optionals (wrap != null) [
"--wrap"
(toString wrap)
]);
};
}