Skip to content

Commit 65c7bc2

Browse files
committed
Include the admonition term at the start of the admonition
This adds the term ("Warning") at the beginning of the admonition with a standardized styling (bold italics, with a colon). This ensures uniform styling.
1 parent 3de8d78 commit 65c7bc2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

mdbook-spec/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,28 @@ impl Spec {
131131
ADMONITION_RE
132132
.replace_all(&chapter.content, |caps: &Captures<'_>| {
133133
let lower = caps["admon"].to_lowercase();
134+
let term = to_initial_case(&caps["admon"]);
135+
let blockquote = &caps["blockquote"];
134136
format!(
135-
"<div class=\"{lower}\">\n\n{}\n\n</div>\n",
136-
&caps["blockquote"]
137+
"<div class=\"{lower}\">\n\
138+
\n\
139+
> ***{term}:***\n\
140+
{blockquote}\n\
141+
\n\
142+
</div>\n",
137143
)
138144
})
139145
.to_string()
140146
}
141147
}
142148

149+
fn to_initial_case(s: &str) -> String {
150+
let mut chars = s.chars();
151+
let first = chars.next().expect("not empty").to_uppercase();
152+
let rest = chars.as_str().to_lowercase();
153+
format!("{first}{rest}")
154+
}
155+
143156
impl Preprocessor for Spec {
144157
fn name(&self) -> &str {
145158
"spec"

0 commit comments

Comments
 (0)