markdown_ppp/printer/
config.rs

1/// Configuration for Markdown pretty-printing output.
2pub struct Config {
3    pub(crate) width: usize,
4    pub(crate) spaces_before_list_item: usize,
5    pub(crate) empty_line_before_list: bool,
6}
7
8impl Default for Config {
9    fn default() -> Self {
10        Self {
11            width: 80,
12            spaces_before_list_item: 1,
13            empty_line_before_list: true,
14        }
15    }
16}
17
18impl Config {
19    /// Render document with a given width in characters.
20    pub fn with_width(self, width: usize) -> Self {
21        Self { width, ..self }
22    }
23
24    /// Sets the number of spaces to insert before each list item when rendering the AST to Markdown.
25    ///
26    /// The default is 1 space. According to the GitHub Flavored Markdown specification,
27    /// between 0 and 3 spaces before a list marker are allowed:
28    /// <https://github.github.com/gfm/#lists>
29    ///
30    /// # Parameters
31    ///
32    /// - `spaces`: the number of spaces to insert before each list item (valid range: 0..=3).
33    ///
34    /// # Returns
35    ///
36    /// A new printer config instance with `spaces_before_list_item` set to the specified value.
37    pub fn with_spaces_before_list_item(self, spaces: usize) -> Self {
38        Self {
39            spaces_before_list_item: spaces,
40            ..self
41        }
42    }
43
44    /// Sets whether to add an empty line before lists.
45    ///
46    /// The default is `true`, which means that lists are preceded by an empty line.
47    pub fn with_empty_line_before_list(self, tight: bool) -> Self {
48        Self {
49            empty_line_before_list: tight,
50            ..self
51        }
52    }
53}