dprint_config/markdown.rs
1//! Configuration for the dprint Markdown plugin.
2//!
3//! See: <https://dprint.dev/plugins/markdown/config/>
4
5use alloc::collections::BTreeMap;
6use alloc::string::String;
7use alloc::vec::Vec;
8
9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13/// See: <https://dprint.dev/plugins/markdown/config/>
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
15pub enum HeadingKind {
16 /// Uses # or ## before the heading text (ATX headings).
17 #[serde(rename = "atx")]
18 Atx,
19 /// Uses an underline of = or - beneath the heading text (setext headings). Only applies to level 1 and 2 headings.
20 #[serde(rename = "setext")]
21 Setext,
22}
23
24/// See: <https://dprint.dev/plugins/markdown/config/>
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
26pub enum NewLineKind {
27 /// For each file, uses the newline kind found at the end of the last line.
28 #[serde(rename = "auto")]
29 Auto,
30 /// Uses carriage return, line feed.
31 #[serde(rename = "crlf")]
32 Crlf,
33 /// Uses line feed.
34 #[serde(rename = "lf")]
35 Lf,
36 /// Uses the system standard (ex. crlf on Windows).
37 #[serde(rename = "system")]
38 System,
39}
40
41/// See: <https://dprint.dev/plugins/markdown/config/>
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
43pub enum StrongKind {
44 /// Uses asterisks (*) for emphasis.
45 #[serde(rename = "asterisks")]
46 Asterisks,
47 /// Uses underscores (_) for emphasis.
48 #[serde(rename = "underscores")]
49 Underscores,
50}
51
52/// See: <https://dprint.dev/plugins/markdown/config/>
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
54pub enum TextWrap {
55 /// Always wraps text.
56 #[serde(rename = "always")]
57 Always,
58 /// Maintains line breaks.
59 #[serde(rename = "maintain")]
60 Maintain,
61 /// Never wraps text.
62 #[serde(rename = "never")]
63 Never,
64}
65
66/// See: <https://dprint.dev/plugins/markdown/config/>
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
68pub enum UnorderedListKind {
69 /// Uses dashes (-) as primary character for lists.
70 #[serde(rename = "dashes")]
71 Dashes,
72 /// Uses asterisks (*) as primary character for lists.
73 #[serde(rename = "asterisks")]
74 Asterisks,
75}
76
77/// Configuration for the dprint [Markdown](https://dprint.dev/plugins/markdown/config/) plugin.
78///
79/// See: <https://dprint.dev/plugins/markdown/config/>
80#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
81#[schemars(title = "Markdown Plugin Configuration")]
82pub struct MarkdownConfig {
83 /// Whether the configuration is not allowed to be overridden or extended.
84 #[serde(default, skip_serializing_if = "Option::is_none")]
85 pub locked: Option<bool>,
86
87 /// File patterns to associate with this plugin.
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 pub associations: Option<Vec<String>>,
90
91 /// Top level configuration that sets the configuration to what is used in Deno.
92 ///
93 /// Default: `false`
94 ///
95 /// See: <https://dprint.dev/plugins/markdown/config/#deno>
96 #[serde(default, skip_serializing_if = "Option::is_none")]
97 pub deno: Option<bool>,
98
99 /// The character to use for emphasis/italics.
100 ///
101 /// Default: `"underscores"`
102 ///
103 /// See: <https://dprint.dev/plugins/markdown/config/#emphasisKind>
104 #[serde(
105 default,
106 rename = "emphasisKind",
107 alias = "emphasis-kind",
108 skip_serializing_if = "Option::is_none"
109 )]
110 pub emphasis_kind: Option<StrongKind>,
111
112 /// The style of heading to use for level 1 and level 2 headings. Level 3 and higher always use ATX headings.
113 ///
114 /// Default: `"atx"`
115 ///
116 /// See: <https://dprint.dev/plugins/markdown/config/#headingKind>
117 #[serde(
118 default,
119 rename = "headingKind",
120 alias = "heading-kind",
121 skip_serializing_if = "Option::is_none"
122 )]
123 pub heading_kind: Option<HeadingKind>,
124
125 /// The text to use for an ignore directive (ex. `<!-- dprint-ignore -->`).
126 ///
127 /// Default: `"dprint-ignore"`
128 ///
129 /// See: <https://dprint.dev/plugins/markdown/config/#ignoreDirective>
130 #[serde(
131 default,
132 rename = "ignoreDirective",
133 alias = "ignore-directive",
134 skip_serializing_if = "Option::is_none"
135 )]
136 pub ignore_directive: Option<String>,
137
138 /// The text to use for an ignore end directive (ex. `<!-- dprint-ignore-end -->`).
139 ///
140 /// Default: `"dprint-ignore-end"`
141 ///
142 /// See: <https://dprint.dev/plugins/markdown/config/#ignoreEndDirective>
143 #[serde(
144 default,
145 rename = "ignoreEndDirective",
146 alias = "ignore-end-directive",
147 skip_serializing_if = "Option::is_none"
148 )]
149 pub ignore_end_directive: Option<String>,
150
151 /// The text to use for an ignore file directive (ex. `<!-- dprint-ignore-file -->`).
152 ///
153 /// Default: `"dprint-ignore-file"`
154 ///
155 /// See: <https://dprint.dev/plugins/markdown/config/#ignoreFileDirective>
156 #[serde(
157 default,
158 rename = "ignoreFileDirective",
159 alias = "ignore-file-directive",
160 skip_serializing_if = "Option::is_none"
161 )]
162 pub ignore_file_directive: Option<String>,
163
164 /// The text to use for an ignore start directive (ex. `<!-- dprint-ignore-start -->`).
165 ///
166 /// Default: `"dprint-ignore-start"`
167 ///
168 /// See: <https://dprint.dev/plugins/markdown/config/#ignoreStartDirective>
169 #[serde(
170 default,
171 rename = "ignoreStartDirective",
172 alias = "ignore-start-directive",
173 skip_serializing_if = "Option::is_none"
174 )]
175 pub ignore_start_directive: Option<String>,
176
177 /// The width of a line the printer will try to stay under. Note that the printer may exceed this width in certain cases.
178 ///
179 /// Default: `80`
180 ///
181 /// See: <https://dprint.dev/plugins/markdown/config/#lineWidth>
182 #[serde(
183 default,
184 rename = "lineWidth",
185 alias = "line-width",
186 skip_serializing_if = "Option::is_none"
187 )]
188 pub line_width: Option<u32>,
189
190 /// The kind of newline to use.
191 ///
192 /// Default: `"lf"`
193 ///
194 /// See: <https://dprint.dev/plugins/markdown/config/#newLineKind>
195 #[serde(
196 default,
197 rename = "newLineKind",
198 alias = "new-line-kind",
199 skip_serializing_if = "Option::is_none"
200 )]
201 pub new_line_kind: Option<NewLineKind>,
202
203 /// The character to use for strong emphasis/bold.
204 ///
205 /// Default: `"asterisks"`
206 ///
207 /// See: <https://dprint.dev/plugins/markdown/config/#strongKind>
208 #[serde(
209 default,
210 rename = "strongKind",
211 alias = "strong-kind",
212 skip_serializing_if = "Option::is_none"
213 )]
214 pub strong_kind: Option<StrongKind>,
215
216 /// Custom tag to file extension mappings for formatting code blocks. For example: { "markdown": "md" }
217 ///
218 /// See: <https://dprint.dev/plugins/markdown/config/#tags>
219 #[serde(default, skip_serializing_if = "Option::is_none")]
220 pub tags: Option<BTreeMap<String, String>>,
221
222 /// Text wrapping possibilities.
223 ///
224 /// Default: `"maintain"`
225 ///
226 /// See: <https://dprint.dev/plugins/markdown/config/#textWrap>
227 #[serde(
228 default,
229 rename = "textWrap",
230 alias = "text-wrap",
231 skip_serializing_if = "Option::is_none"
232 )]
233 pub text_wrap: Option<TextWrap>,
234
235 /// The character to use for unordered lists.
236 ///
237 /// Default: `"dashes"`
238 ///
239 /// See: <https://dprint.dev/plugins/markdown/config/#unorderedListKind>
240 #[serde(
241 default,
242 rename = "unorderedListKind",
243 alias = "unordered-list-kind",
244 skip_serializing_if = "Option::is_none"
245 )]
246 pub unordered_list_kind: Option<UnorderedListKind>,
247
248 /// Additional plugin-specific settings not covered by the typed fields.
249 #[serde(flatten)]
250 pub extra: BTreeMap<String, Value>,
251}