Skip to main content

socketry_markdown/markdown/
configure.rs

1// Released under the MIT License.
2// Copyright, 2024, by Bnchi.
3// Copyright, 2024, by Titus Wormer.
4// Copyright, 2026, by Samuel Williams.
5
6//! Configuration.
7//!
8//! JS equivalent: https://github.com/syntax-tree/mdast-util-to-markdown/blob/fd6a508/lib/types.js#L307.
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10/// Configuration for indent of lists.
11pub enum IndentOptions {
12    /// Depends on the item and its parent list: uses `IndentOptions::One` if
13    /// the item and list are tight and `IndentOptions::Tab` otherwise.
14    Mixed,
15    /// The size of the bullet plus one space.
16    One,
17    /// Tab stop.
18    Tab,
19}
20
21/// Configuration.
22#[derive(Clone, Debug)]
23pub struct Options {
24    /// Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or
25    /// `'-'`, default: `'*'`).
26    pub bullet: char,
27    /// Marker to use for bullets of items in ordered lists (`'.'` or `')'`,
28    /// default: `'.'`).
29    pub bullet_ordered: char,
30    /// Marker to use in certain cases where the primary bullet doesn’t work
31    /// (`'*'`, `'+'`, or `'-'`, default: `'-'` when bullet is `'*'`, `'*'`
32    /// otherwise).
33    pub bullet_other: char,
34    /// Whether to add the same number of number signs (`#`) at the end of an
35    /// ATX heading as the opening sequence (`bool`, default: `false`).
36    pub close_atx: bool,
37    /// Marker to use for emphasis (`'*'` or `'_'`, default: `'*'`).
38    pub emphasis: char,
39    /// Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``).
40    pub fence: char,
41    /// Whether to use fenced code always (`bool`, default: `true`).
42    /// The default is to use fenced code if there is a language defined,
43    /// if the code is empty,
44    /// or if it starts or ends in blank lines.
45    pub fences: bool,
46    /// Whether to increment the counter of ordered lists items (`bool`,
47    /// default: `true`).
48    pub increment_list_marker: bool,
49    /// How to indent the content of list items (default: `IndentOptions::One`).
50    pub list_item_indent: IndentOptions,
51    /// Marker to use for titles (`'"'` or `"'"`, default: `'"'`).
52    pub quote: char,
53    /// Whether to always use resource links (`bool`, default: `false`).
54    /// The default is to use autolinks (`<https://example.com>`) when possible
55    /// and resource links (`[text](url)`) otherwise.
56    pub resource_link: bool,
57    /// Marker to use for thematic breaks (`'*'`, `'-'`, or `'_'`, default:
58    /// `'*'`).
59    pub rule: char,
60    /// Number of markers to use for thematic breaks (`u32`, default: `3`, min:
61    /// `3`).
62    pub rule_repetition: u32,
63    /// Whether to add spaces between markers in thematic breaks (`bool`,
64    /// default: `false`).
65    pub rule_spaces: bool,
66    /// Whether to use setext headings when possible (`bool`, default:
67    /// `false`).
68    /// The default is to always use ATX headings (`# heading`) instead of
69    /// setext headings (`heading\n=======`).
70    /// Setext headings cannot be used for empty headings or headings with a
71    /// rank of three or more.
72    pub setext: bool,
73    /// Whether to support math (text) with a single dollar (`bool`, default: `true`).
74    /// Single dollars work in Pandoc and many other places, but often interfere with “normal”
75    /// dollars in text.
76    /// If you turn this off, you can still use two or more dollars for text math.
77    pub single_dollar_text_math: bool,
78    /// Marker to use for strong (`'*'` or `'_'`, default: `'*'`).
79    pub strong: char,
80    /// Whether to join definitions without a blank line (`bool`, default:
81    /// `false`).
82    pub tight_definitions: bool,
83}
84
85impl Default for Options {
86    fn default() -> Self {
87        Self {
88            bullet: '*',
89            bullet_ordered: '.',
90            bullet_other: '-',
91            close_atx: false,
92            emphasis: '*',
93            fence: '`',
94            fences: true,
95            increment_list_marker: true,
96            list_item_indent: IndentOptions::One,
97            quote: '"',
98            resource_link: false,
99            rule: '*',
100            rule_repetition: 3,
101            rule_spaces: false,
102            setext: false,
103            single_dollar_text_math: true,
104            strong: '*',
105            tight_definitions: false,
106        }
107    }
108}