@@ -11,7 +11,6 @@ static ADMONITION_RE: LazyLock<Regex> = LazyLock::new(|| {
11
11
Regex :: new ( r"(?m)^ *> \[!(?<admon>[^]]+)\]\n(?<blockquote>(?: *>.*\n)+)" ) . unwrap ( )
12
12
} ) ;
13
13
14
-
15
14
// This icon is from GitHub, MIT License, see https://github.com/primer/octicons
16
15
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
16
@@ -38,16 +37,28 @@ pub fn admonitions(chapter: &Chapter, diag: &mut Diagnostics) -> String {
38
37
let blockquote = & caps[ "blockquote" ] ;
39
38
let initial_spaces = blockquote. chars ( ) . position ( |ch| ch != ' ' ) . unwrap_or ( 0 ) ;
40
39
let space = & blockquote[ ..initial_spaces] ;
41
- if lower. starts_with ( "edition-" ) {
42
- let edition = & lower[ 8 ..] ;
43
- return format ! ( "{space}<div class=\" alert alert-edition\" >\n \
40
+
41
+ let format_div = |class, content| {
42
+ format ! (
43
+ "{space}<div class=\" alert alert-{class}\" >\n \
44
44
\n \
45
45
{space}> <p class=\" alert-title\" >\
46
- <span class= \" alert-title-edition \" >{edition}</span> Edition differences </p>\n \
46
+ {content} </p>\n \
47
47
{space} >\n \
48
48
{blockquote}\n \
49
49
\n \
50
- {space}</div>\n ") ;
50
+ {space}</div>\n ",
51
+ )
52
+ } ;
53
+
54
+ if lower. starts_with ( "edition-" ) {
55
+ let edition = & lower[ 8 ..] ;
56
+ return format_div (
57
+ "edition" ,
58
+ format ! (
59
+ "<span class=\" alert-title-edition\" >{edition}</span> Edition differences"
60
+ ) ,
61
+ ) ;
51
62
}
52
63
53
64
let svg = match lower. as_str ( ) {
@@ -62,17 +73,13 @@ pub fn admonitions(chapter: &Chapter, diag: &mut Diagnostics) -> String {
62
73
""
63
74
}
64
75
} ;
65
- format ! (
66
- "{space}<div class=\" alert alert-{lower}\" >\n \
67
- \n \
68
- {space}> <p class=\" alert-title\" >\
69
- <svg viewBox=\" 0 0 16 16\" width=\" 18\" height=\" 18\" >\
76
+ format_div (
77
+ & lower,
78
+ format ! (
79
+ "<svg viewBox=\" 0 0 16 16\" width=\" 18\" height=\" 18\" >\
70
80
{svg}\
71
- </svg>{term}</p>\n \
72
- {space} >\n \
73
- {blockquote}\n \
74
- \n \
75
- {space}</div>\n ",
81
+ </svg>{term}"
82
+ ) ,
76
83
)
77
84
} )
78
85
. to_string ( )
0 commit comments