@@ -2,9 +2,24 @@ use config::Config;
22
33mod common;
44
5- fn render_codeblock ( content : & str , highlight_code : bool ) -> String {
5+ enum HighlightMode {
6+ None ,
7+ Inlined ,
8+ Classed ,
9+ }
10+
11+ fn render_codeblock ( content : & str , highlight_mode : HighlightMode ) -> String {
612 let mut config = Config :: default_for_test ( ) ;
7- config. markdown . highlight_code = highlight_code;
13+ match highlight_mode {
14+ HighlightMode :: None => { }
15+ HighlightMode :: Inlined => {
16+ config. markdown . highlight_code = true ;
17+ }
18+ HighlightMode :: Classed => {
19+ config. markdown . highlight_code = true ;
20+ config. markdown . highlight_theme = "css" . to_owned ( ) ;
21+ }
22+ }
823 common:: render_with_config ( content, config) . unwrap ( ) . body
924}
1025
1732bar
1833```
1934 "# ,
20- false ,
35+ HighlightMode :: None ,
2136 ) ;
2237 insta:: assert_snapshot!( body) ;
2338}
3348bat
3449```
3550 "# ,
36- true ,
51+ HighlightMode :: Inlined ,
3752 ) ;
3853 insta:: assert_snapshot!( body) ;
3954}
4964baz
5065```
5166 "# ,
52- true ,
67+ HighlightMode :: Inlined ,
5368 ) ;
5469 insta:: assert_snapshot!( body) ;
5570}
6580baz
6681```
6782 "# ,
68- true ,
83+ HighlightMode :: Inlined ,
6984 ) ;
7085 insta:: assert_snapshot!( body) ;
7186}
8196baz
8297```
8398 "# ,
84- true ,
99+ HighlightMode :: Inlined ,
85100 ) ;
86101 insta:: assert_snapshot!( body) ;
87102}
97112baz
98113```
99114 "# ,
100- true ,
115+ HighlightMode :: Inlined ,
101116 ) ;
102117 let body2 = render_codeblock (
103118 r#"
108123baz
109124```
110125 "# ,
111- true ,
126+ HighlightMode :: Inlined ,
112127 ) ;
113128 assert_eq ! ( body, body2) ;
114129}
124139baz
125140```
126141 "# ,
127- true ,
142+ HighlightMode :: Inlined ,
128143 ) ;
129144 insta:: assert_snapshot!( body) ;
130145}
140155baz
141156```
142157 "# ,
143- true ,
158+ HighlightMode :: Inlined ,
144159 ) ;
145160 insta:: assert_snapshot!( body) ;
146161}
156171baz
157172```
158173 "# ,
159- true ,
174+ HighlightMode :: Inlined ,
160175 ) ;
161176 insta:: assert_snapshot!( body) ;
162177}
172187baz
173188```
174189 "# ,
175- true ,
190+ HighlightMode :: Inlined ,
176191 ) ;
177192 insta:: assert_snapshot!( body) ;
178193}
188203baz
189204```
190205 "# ,
191- true ,
206+ HighlightMode :: Inlined ,
192207 ) ;
193208 insta:: assert_snapshot!( body) ;
194209}
204219baz
205220```
206221 "# ,
207- true ,
222+ HighlightMode :: Inlined ,
208223 ) ;
209224 insta:: assert_snapshot!( body) ;
210225}
220235baz
221236```
222237 "# ,
223- true ,
238+ HighlightMode :: Inlined ,
239+ ) ;
240+ insta:: assert_snapshot!( body) ;
241+ }
242+
243+ #[ test]
244+ fn can_highlight_with_classes ( ) {
245+ let body = render_codeblock (
246+ r#"
247+ ```html,hl_lines=3-4
248+ <link
249+ rel="stylesheet"
250+ type="text/css"
251+ href="main.css"
252+ />
253+ ```
254+ "# ,
255+ HighlightMode :: Classed ,
224256 ) ;
225257 insta:: assert_snapshot!( body) ;
226258}
@@ -234,14 +266,14 @@ foo
234266bar
235267```
236268 "# ,
237- true ,
269+ HighlightMode :: Inlined ,
238270 ) ;
239271 insta:: assert_snapshot!( body) ;
240272}
241273
242274#[ test]
243275fn can_add_line_numbers_windows_eol ( ) {
244- let body = render_codeblock ( "```linenos\r \n foo\r \n bar\r \n ```\r \n " , true ) ;
276+ let body = render_codeblock ( "```linenos\r \n foo\r \n bar\r \n ```\r \n " , HighlightMode :: Inlined ) ;
245277 insta:: assert_snapshot!( body) ;
246278}
247279
254286bar
255287```
256288 "# ,
257- true ,
289+ HighlightMode :: Inlined ,
258290 ) ;
259291 insta:: assert_snapshot!( body) ;
260292}
268300bar
269301```
270302 "# ,
271- true ,
303+ HighlightMode :: Inlined ,
304+ ) ;
305+ insta:: assert_snapshot!( body) ;
306+ }
307+
308+ #[ test]
309+ fn can_add_line_numbers_with_classes ( ) {
310+ let body = render_codeblock (
311+ r#"
312+ ```html,linenos
313+ <link
314+ rel="stylesheet"
315+ type="text/css"
316+ href="main.css"
317+ />
318+ ```
319+ "# ,
320+ HighlightMode :: Classed ,
272321 ) ;
273322 insta:: assert_snapshot!( body) ;
274323}
@@ -283,7 +332,7 @@ fn can_render_shortcode_in_codeblock() {
283332</div>
284333```
285334 "# ,
286- true ,
335+ HighlightMode :: Inlined ,
287336 ) ;
288337 insta:: assert_snapshot!( body) ;
289338}
@@ -300,7 +349,7 @@ text2
300349text3
301350```
302351 "# ,
303- true ,
352+ HighlightMode :: Inlined ,
304353 ) ;
305354 insta:: assert_snapshot!( body) ;
306355}
@@ -323,7 +372,7 @@ A quote
323372<!-- end text goes here -->
324373```
325374 "# ,
326- true ,
375+ HighlightMode :: Inlined ,
327376 ) ;
328377 insta:: assert_snapshot!( body) ;
329378}
337386bar
338387```
339388 "# ,
340- true ,
389+ HighlightMode :: Inlined ,
341390 ) ;
342391 insta:: assert_snapshot!( body) ;
343392}
0 commit comments