@@ -171,13 +171,15 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
171
171
let event = self . inner . next ( ) ;
172
172
let compile_fail;
173
173
let ignore;
174
+ let edition;
174
175
if let Some ( Event :: Start ( Tag :: CodeBlock ( lang) ) ) = event {
175
176
let parse_result = LangString :: parse ( & lang, self . check_error_codes ) ;
176
177
if !parse_result. rust {
177
178
return Some ( Event :: Start ( Tag :: CodeBlock ( lang) ) ) ;
178
179
}
179
180
compile_fail = parse_result. compile_fail ;
180
181
ignore = parse_result. ignore ;
182
+ edition = parse_result. edition ;
181
183
} else {
182
184
return event;
183
185
}
@@ -213,6 +215,17 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
213
215
} else {
214
216
""
215
217
} ;
218
+
219
+ let edition_string = if let Some ( e @ Edition :: Edition2018 ) = edition {
220
+ format ! ( "&edition={}{}" , e,
221
+ if channel == "&version=nightly" { "" }
222
+ else { "&version=nightly" } )
223
+ } else if let Some ( e) = edition {
224
+ format ! ( "&edition={}" , e)
225
+ } else {
226
+ "" . to_owned ( )
227
+ } ;
228
+
216
229
// These characters don't need to be escaped in a URI.
217
230
// FIXME: use a library function for percent encoding.
218
231
fn dont_escape ( c : u8 ) -> bool {
@@ -232,26 +245,44 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
232
245
}
233
246
}
234
247
Some ( format ! (
235
- r#"<a class="test-arrow" target="_blank" href="{}?code={}{}">Run</a>"# ,
236
- url, test_escaped, channel
248
+ r#"<a class="test-arrow" target="_blank" href="{}?code={}{}{} ">Run</a>"# ,
249
+ url, test_escaped, channel, edition_string
237
250
) )
238
251
} ) ;
252
+
239
253
let tooltip = if ignore {
240
- Some ( ( "This example is not tested" , "ignore" ) )
254
+ Some ( ( "This example is not tested" . to_owned ( ) , "ignore" ) )
241
255
} else if compile_fail {
242
- Some ( ( "This example deliberately fails to compile" , "compile_fail" ) )
256
+ Some ( ( "This example deliberately fails to compile" . to_owned ( ) , "compile_fail" ) )
257
+ } else if let Some ( e) = edition {
258
+ Some ( ( format ! ( "This code runs with edition {}" , e) , "edition" ) )
243
259
} else {
244
260
None
245
261
} ;
246
- s. push_str ( & highlight:: render_with_highlighting (
247
- & text,
248
- Some ( & format ! ( "rust-example-rendered{}" ,
249
- if ignore { " ignore" }
250
- else if compile_fail { " compile_fail" }
251
- else { "" } ) ) ,
252
- playground_button. as_ref ( ) . map ( String :: as_str) ,
253
- tooltip) ) ;
254
- Some ( Event :: Html ( s. into ( ) ) )
262
+
263
+ if let Some ( ( s1, s2) ) = tooltip {
264
+ s. push_str ( & highlight:: render_with_highlighting (
265
+ & text,
266
+ Some ( & format ! ( "rust-example-rendered{}" ,
267
+ if ignore { " ignore" }
268
+ else if compile_fail { " compile_fail" }
269
+ else if edition. is_some( ) { " edition " }
270
+ else { "" } ) ) ,
271
+ playground_button. as_ref ( ) . map ( String :: as_str) ,
272
+ Some ( ( s1. as_str ( ) , s2) ) ) ) ;
273
+ Some ( Event :: Html ( s. into ( ) ) )
274
+ } else {
275
+ s. push_str ( & highlight:: render_with_highlighting (
276
+ & text,
277
+ Some ( & format ! ( "rust-example-rendered{}" ,
278
+ if ignore { " ignore" }
279
+ else if compile_fail { " compile_fail" }
280
+ else if edition. is_some( ) { " edition " }
281
+ else { "" } ) ) ,
282
+ playground_button. as_ref ( ) . map ( String :: as_str) ,
283
+ None ) ) ;
284
+ Some ( Event :: Html ( s. into ( ) ) )
285
+ }
255
286
} )
256
287
}
257
288
}
0 commit comments