forked from numtide/treefmt-nix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdformat.nix
More file actions
121 lines (114 loc) · 2.58 KB
/
Copy pathmdformat.nix
File metadata and controls
121 lines (114 loc) · 2.58 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
config,
lib,
mkFormatterModule,
...
}:
let
cfg = config.programs.mdformat;
in
{
meta.maintainers = [ "sebaszv" ];
imports = [
(mkFormatterModule {
name = "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 =
let
inherit (lib.types)
bool
enum
functionTo
int
listOf
nullOr
oneOf
package
;
in
{
plugins = lib.mkOption {
description = ''
Plugins for mdformat that extend its functionality (for Markdown
extensions, formatting code blocks, etc).
See [mdformat docs](https://mdformat.readthedocs.io/en/stable/users/plugins.html)
for a (non-exhaustive) list of plugins.
'';
type = functionTo (listOf package);
default = _: [ ];
defaultText = lib.literalExpression ''
ps: [ ];
'';
example = lib.literalExpression ''
ps: [
ps.mdformat-footnote
ps.mdformat-gfm
];
'';
};
settings = {
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 {
programs.mdformat.finalPackage = cfg.package.withPlugins cfg.plugins;
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)
]);
};
}