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 for soft line breaks in phrasing content.
22#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
23pub enum LineWrapping {
24 /// Preserve soft line breaks from the syntax tree (the default).
25 #[default]
26 Preserve,
27 /// Replace soft line breaks with spaces.
28 ///
29 /// Explicit Markdown hard breaks, code, and block boundaries are preserved.
30 Unwrap,
31}
32
33/// Configuration.
34#[derive(Clone, Debug)]
35pub struct Options {
36 /// How to handle soft line breaks in text (default: `LineWrapping::Preserve`).
37 pub line_wrapping: LineWrapping,
38 /// Marker to use for bullets of items in unordered lists (`'*'`, `'+'`, or
39 /// `'-'`, default: `'-'`).
40 pub bullet: char,
41 /// Marker to use for bullets of items in ordered lists (`'.'` or `')'`,
42 /// default: `'.'`).
43 pub bullet_ordered: char,
44 /// Marker to use in certain cases where the primary bullet doesn’t work
45 /// (`'*'`, `'+'`, or `'-'`, default: `'-'` when bullet is `'*'`, `'*'`
46 /// otherwise).
47 pub bullet_other: char,
48 /// Whether to add the same number of number signs (`#`) at the end of an
49 /// ATX heading as the opening sequence (`bool`, default: `false`).
50 pub close_atx: bool,
51 /// Marker to use for emphasis (`'*'` or `'_'`, default: `'*'`).
52 pub emphasis: char,
53 /// Marker to use for fenced code (``'`'`` or `'~'`, default: ``'`'``).
54 pub fence: char,
55 /// Whether to use fenced code always (`bool`, default: `true`).
56 /// The default is to use fenced code if there is a language defined,
57 /// if the code is empty,
58 /// or if it starts or ends in blank lines.
59 pub fences: bool,
60 /// Whether to increment the counter of ordered lists items (`bool`,
61 /// default: `true`).
62 pub increment_list_marker: bool,
63 /// How to indent the content of list items (default: `IndentOptions::One`).
64 pub list_item_indent: IndentOptions,
65 /// Marker to use for titles (`'"'` or `"'"`, default: `'"'`).
66 pub quote: char,
67 /// Whether to always use resource links (`bool`, default: `false`).
68 /// The default is to use autolinks (`<https://example.com>`) when possible
69 /// and resource links (`[text](url)`) otherwise.
70 pub resource_link: bool,
71 /// Marker to use for thematic breaks (`'*'`, `'-'`, or `'_'`, default:
72 /// `'*'`).
73 pub rule: char,
74 /// Number of markers to use for thematic breaks (`u32`, default: `3`, min:
75 /// `3`).
76 pub rule_repetition: u32,
77 /// Whether to add spaces between markers in thematic breaks (`bool`,
78 /// default: `false`).
79 pub rule_spaces: bool,
80 /// Whether to use setext headings when possible (`bool`, default:
81 /// `false`).
82 /// The default is to always use ATX headings (`# heading`) instead of
83 /// setext headings (`heading\n=======`).
84 /// Setext headings cannot be used for empty headings or headings with a
85 /// rank of three or more.
86 pub setext: bool,
87 /// Whether to support math (text) with a single dollar (`bool`, default: `true`).
88 /// Single dollars work in Pandoc and many other places, but often interfere with “normal”
89 /// dollars in text.
90 /// If you turn this off, you can still use two or more dollars for text math.
91 pub single_dollar_text_math: bool,
92 /// Marker to use for strong (`'*'` or `'_'`, default: `'*'`).
93 pub strong: char,
94 /// Whether to join definitions without a blank line (`bool`, default:
95 /// `false`).
96 pub tight_definitions: bool,
97}
98
99impl Default for Options {
100 fn default() -> Self {
101 Self {
102 line_wrapping: LineWrapping::default(),
103 bullet: '-',
104 bullet_ordered: '.',
105 bullet_other: '-',
106 close_atx: false,
107 emphasis: '*',
108 fence: '`',
109 fences: true,
110 increment_list_marker: true,
111 list_item_indent: IndentOptions::One,
112 quote: '"',
113 resource_link: false,
114 rule: '*',
115 rule_repetition: 3,
116 rule_spaces: false,
117 setext: false,
118 single_dollar_text_math: true,
119 strong: '*',
120 tight_definitions: false,
121 }
122 }
123}