1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
pub(crate) fn is_built_in_context(context: &str) -> bool {
matches!(
context,
"admonition"
| "audio"
| "colist"
| "dlist"
| "document"
| "example"
| "floating_title"
| "image"
| "list_item"
| "listing"
| "literal"
| "olist"
| "open"
| "page_break"
| "paragraph"
| "pass"
| "preamble"
| "quote"
| "section"
| "sidebar"
| "stem"
| "table"
| "table_cell"
| "thematic_break"
| "toc"
| "ulist"
| "verse"
| "video"
)
}
/// The five admonition types provided by the AsciiDoc language.
///
/// An admonition draws attention to a statement by taking it out of the
/// content's flow and labeling it with a priority. The variant is determined by
/// the assigned type (i.e., the uppercase label), which is specified either as
/// a special paragraph prefix (e.g., `NOTE:`) or as the block style in an
/// attribute list (e.g., `[NOTE]`).
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum AdmonitionVariant {
/// The `NOTE` admonition type.
Note,
/// The `TIP` admonition type.
Tip,
/// The `IMPORTANT` admonition type.
Important,
/// The `CAUTION` admonition type.
Caution,
/// The `WARNING` admonition type.
Warning,
}
impl AdmonitionVariant {
/// Resolve an uppercase style label (e.g., `NOTE`) to its admonition
/// variant, if it names one.
///
/// The match is case-sensitive: the label must be uppercase, per the
/// AsciiDoc language specification.
pub(crate) fn from_style(style: &str) -> Option<Self> {
Some(match style {
"NOTE" => Self::Note,
"TIP" => Self::Tip,
"IMPORTANT" => Self::Important,
"CAUTION" => Self::Caution,
"WARNING" => Self::Warning,
_ => return None,
})
}
/// Returns the uppercase style label for this variant (e.g., `NOTE`).
pub fn style(self) -> &'static str {
match self {
Self::Note => "NOTE",
Self::Tip => "TIP",
Self::Important => "IMPORTANT",
Self::Caution => "CAUTION",
Self::Warning => "WARNING",
}
}
/// Returns the lowercase name for this variant (e.g., `note`).
///
/// This is the name used for the block's CSS class and for the
/// `<type>-caption` document attribute that controls the label text.
pub fn name(self) -> &'static str {
match self {
Self::Note => "note",
Self::Tip => "tip",
Self::Important => "important",
Self::Caution => "caution",
Self::Warning => "warning",
}
}
/// Returns the default caption (label) text for this variant (e.g.,
/// `Note`).
///
/// This text is shown to the reader (in place of an icon) unless it is
/// overridden by setting the `<type>-caption` document attribute.
pub fn default_caption(self) -> &'static str {
match self {
Self::Note => "Note",
Self::Tip => "Tip",
Self::Important => "Important",
Self::Caution => "Caution",
Self::Warning => "Warning",
}
}
}
impl std::fmt::Debug for AdmonitionVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Note => write!(f, "AdmonitionVariant::Note"),
Self::Tip => write!(f, "AdmonitionVariant::Tip"),
Self::Important => write!(f, "AdmonitionVariant::Important"),
Self::Caution => write!(f, "AdmonitionVariant::Caution"),
Self::Warning => write!(f, "AdmonitionVariant::Warning"),
}
}
}