Skip to content

Commit e45f7f0

Browse files
committed
Move icons to separately defined consts
This is just to help clean up the size of the function.
1 parent 987ae0c commit e45f7f0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mdbook-spec/src/admonitions.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ static ADMONITION_RE: LazyLock<Regex> = LazyLock::new(|| {
1111
Regex::new(r"(?m)^ *> \[!(?<admon>[^]]+)\]\n(?<blockquote>(?: *>.*\n)+)").unwrap()
1212
});
1313

14+
15+
// This icon is from GitHub, MIT License, see https://github.com/primer/octicons
16+
const ICON_NOTE: &str = r#"<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>"#;
17+
18+
// This icon is from GitHub, MIT License, see https://github.com/primer/octicons
19+
const ICON_WARNING: &str = r#"<path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>"#;
20+
1421
/// Converts blockquotes with special headers into admonitions.
1522
///
1623
/// The blockquote should look something like:
@@ -43,10 +50,9 @@ pub fn admonitions(chapter: &Chapter, diag: &mut Diagnostics) -> String {
4350
{space}</div>\n");
4451
}
4552

46-
// These icons are from GitHub, MIT License, see https://github.com/primer/octicons
4753
let svg = match lower.as_str() {
48-
"note" => "<path d=\"M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z\"></path>",
49-
"warning" => "<path d=\"M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z\"></path>",
54+
"note" => ICON_NOTE,
55+
"warning" => ICON_WARNING,
5056
_ => {
5157
warn_or_err!(
5258
diag,

0 commit comments

Comments
 (0)