@@ -33,6 +33,7 @@ use std::str;
33
33
34
34
use crate :: clean:: RenderedLink ;
35
35
use crate :: doctest;
36
+ use crate :: html:: escape:: Escape ;
36
37
use crate :: html:: highlight;
37
38
use crate :: html:: toc:: TocBuilder ;
38
39
@@ -207,26 +208,11 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
207
208
let should_panic;
208
209
let ignore;
209
210
let edition;
210
- if let Some ( Event :: Start ( Tag :: CodeBlock ( kind) ) ) = event {
211
- let parse_result = match kind {
212
- CodeBlockKind :: Fenced ( ref lang) => {
213
- LangString :: parse_without_check ( & lang, self . check_error_codes , false )
214
- }
215
- CodeBlockKind :: Indented => Default :: default ( ) ,
216
- } ;
217
- if !parse_result. rust {
218
- return Some ( Event :: Start ( Tag :: CodeBlock ( kind) ) ) ;
219
- }
220
- compile_fail = parse_result. compile_fail ;
221
- should_panic = parse_result. should_panic ;
222
- ignore = parse_result. ignore ;
223
- edition = parse_result. edition ;
211
+ let kind = if let Some ( Event :: Start ( Tag :: CodeBlock ( kind) ) ) = event {
212
+ kind
224
213
} else {
225
214
return event;
226
- }
227
-
228
- let explicit_edition = edition. is_some ( ) ;
229
- let edition = edition. unwrap_or ( self . edition ) ;
215
+ } ;
230
216
231
217
let mut origtext = String :: new ( ) ;
232
218
for event in & mut self . inner {
@@ -241,6 +227,35 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
241
227
let lines = origtext. lines ( ) . filter_map ( |l| map_line ( l) . for_html ( ) ) ;
242
228
let text = lines. collect :: < Vec < Cow < ' _ , str > > > ( ) . join ( "\n " ) ;
243
229
230
+ let parse_result = match kind {
231
+ CodeBlockKind :: Fenced ( ref lang) => {
232
+ let parse_result =
233
+ LangString :: parse_without_check ( & lang, self . check_error_codes , false ) ;
234
+ if !parse_result. rust {
235
+ return Some ( Event :: Html (
236
+ format ! (
237
+ "<div class=\" example-wrap\" >\
238
+ <pre{}>{}</pre>\
239
+ </div>",
240
+ format!( " class=\" language-{}\" " , lang) ,
241
+ Escape ( & text) ,
242
+ )
243
+ . into ( ) ,
244
+ ) ) ;
245
+ }
246
+ parse_result
247
+ }
248
+ CodeBlockKind :: Indented => Default :: default ( ) ,
249
+ } ;
250
+
251
+ compile_fail = parse_result. compile_fail ;
252
+ should_panic = parse_result. should_panic ;
253
+ ignore = parse_result. ignore ;
254
+ edition = parse_result. edition ;
255
+
256
+ let explicit_edition = edition. is_some ( ) ;
257
+ let edition = edition. unwrap_or ( self . edition ) ;
258
+
244
259
let playground_button = self . playground . as_ref ( ) . and_then ( |playground| {
245
260
let krate = & playground. crate_name ;
246
261
let url = & playground. url ;
0 commit comments