@@ -75,20 +75,7 @@ defmodule ExDoc.Markdown.EarmarkTest do
75
75
]
76
76
end
77
77
78
- test "converts blockquote admonitions to regular divs" do
79
- info = """
80
- > #### Info {: .info .ignore}
81
- > This is info.
82
- """
83
-
84
- assert Markdown . to_ast ( info , [ ] ) == [
85
- { :section , [ class: "admonition info" , role: "note" ] ,
86
- [
87
- { :h4 , [ class: "admonition-title ignore info" ] , [ "Info" ] , % { } } ,
88
- { :p , [ ] , [ "This is info." ] , % { } }
89
- ] , % { } }
90
- ]
91
-
78
+ test "leaves blockquotes with the wrong markup as is" do
92
79
not_admonition = """
93
80
> ### H3 {: .xyz}
94
81
> This is NOT an admonition!
@@ -102,18 +89,80 @@ defmodule ExDoc.Markdown.EarmarkTest do
102
89
] , % { } }
103
90
]
104
91
92
+ no_h_tag_beginning = """
93
+ > {: .warning}
94
+ > #### Warning {: .warning}
95
+ > This blockquote didn't start with the h4 tag, so it wasn't converted.
96
+ """
97
+
98
+ assert Markdown . to_ast ( no_h_tag_beginning , [ ] ) == [
99
+ { :blockquote , [ ] ,
100
+ [
101
+ { :p , [ ] , [ "{: .warning}" ] , % { } } ,
102
+ { :h4 , [ class: "warning" ] , [ "Warning" ] , % { } } ,
103
+ { :p , [ ] ,
104
+ [ "This blockquote didn't start with the h4 tag, so it wasn't converted." ] , % { } }
105
+ ] , % { } }
106
+ ]
107
+ end
108
+
109
+ test "converts blockquotes with the appropriate markup to admonition sections" do
110
+ info = """
111
+ > #### Info {: .info .ignore}
112
+ > This is info.
113
+ """
114
+
115
+ assert [
116
+ { :section , section_attrs ,
117
+ [
118
+ { :h4 , h_attrs , [ "Info" ] , % { } } ,
119
+ { :p , [ ] , [ "This is info." ] , % { } }
120
+ ] , % { } }
121
+ ] = Markdown . to_ast ( info , [ ] )
122
+
123
+ assert section_attrs [ :role ] == "note"
124
+ assert section_attrs [ :class ] == "admonition info"
125
+
126
+ assert h_attrs [ :class ] == "admonition-title ignore info"
127
+
105
128
warning_error = """
106
129
> ### Warning! Error! {: .warning .error}
107
130
> A warning and an error.
108
131
"""
109
132
110
- assert Markdown . to_ast ( warning_error , [ ] ) == [
111
- { :section , [ class: "admonition error warning" , role: "note" ] ,
133
+ assert [
134
+ { :section , section_attrs ,
112
135
[
113
- { :h3 , [ class: "admonition-title error warning" ] , [ "Warning! Error!" ] , % { } } ,
136
+ { :h3 , h_attrs , [ "Warning! Error!" ] , % { } } ,
114
137
{ :p , [ ] , [ "A warning and an error." ] , % { } }
115
138
] , % { } }
116
- ]
139
+ ] = Markdown . to_ast ( warning_error , [ ] )
140
+
141
+ assert section_attrs [ :role ] == "note"
142
+ assert section_attrs [ :class ] == "admonition error warning"
143
+
144
+ assert h_attrs [ :class ] == "admonition-title error warning"
145
+
146
+ with_blockquote_level_attrs = """
147
+ > ### Eggs and baskets {: .tip}
148
+ > Don't put all your eggs in one basket, especially if they're golden.
149
+ {: .egg-basket-bg #egg-basket-tip}
150
+ """
151
+
152
+ assert [
153
+ { :section , section_attrs ,
154
+ [
155
+ { :h3 , h_attrs , [ "Eggs and baskets" ] , % { } } ,
156
+ { :p , [ ] ,
157
+ [ "Don't put all your eggs in one basket, especially if they're golden." ] , % { } }
158
+ ] , % { } }
159
+ ] = Markdown . to_ast ( with_blockquote_level_attrs , [ ] )
160
+
161
+ assert section_attrs [ :role ] == "note"
162
+ assert section_attrs [ :class ] == "admonition tip egg-basket-bg"
163
+ assert section_attrs [ :id ] == "egg-basket-tip"
164
+
165
+ assert h_attrs [ :class ] == "admonition-title tip"
117
166
end
118
167
119
168
test "keeps math syntax without interpreting math as markdown" do
0 commit comments