comrak/parser/
alert.rs

1/// The metadata of an Alert node.
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct NodeAlert {
4    /// Type of alert
5    pub alert_type: AlertType,
6
7    /// Overridden title. If None, then use the default title.
8    pub title: Option<String>,
9
10    /// Originated from a multiline blockquote.
11    pub multiline: bool,
12
13    /// The length of the fence (multiline only).
14    pub fence_length: usize,
15
16    /// The indentation level of the fence marker (multiline only)
17    pub fence_offset: usize,
18}
19
20/// The type of alert.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
22pub enum AlertType {
23    /// Useful information that users should know, even when skimming content
24    #[default]
25    Note,
26
27    /// Helpful advice for doing things better or more easily
28    Tip,
29
30    /// Key information users need to know to achieve their goal
31    Important,
32
33    /// Urgent info that needs immediate user attention to avoid problems
34    Warning,
35
36    /// Advises about risks or negative outcomes of certain actions
37    Caution,
38}
39
40impl AlertType {
41    /// Returns the default title for an alert type
42    pub(crate) fn default_title(&self) -> String {
43        match *self {
44            AlertType::Note => String::from("Note"),
45            AlertType::Tip => String::from("Tip"),
46            AlertType::Important => String::from("Important"),
47            AlertType::Warning => String::from("Warning"),
48            AlertType::Caution => String::from("Caution"),
49        }
50    }
51
52    /// Returns the CSS class to use for an alert type
53    pub(crate) fn css_class(&self) -> String {
54        match *self {
55            AlertType::Note => String::from("markdown-alert-note"),
56            AlertType::Tip => String::from("markdown-alert-tip"),
57            AlertType::Important => String::from("markdown-alert-important"),
58            AlertType::Warning => String::from("markdown-alert-warning"),
59            AlertType::Caution => String::from("markdown-alert-caution"),
60        }
61    }
62}