markdown_ppp/printer/
config.rs

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