@@ -33,6 +33,7 @@ use std::str;
3333
3434use crate :: clean:: RenderedLink ;
3535use crate :: doctest;
36+ use crate :: html:: escape:: Escape ;
3637use crate :: html:: highlight;
3738use crate :: html:: toc:: TocBuilder ;
3839
@@ -207,26 +208,11 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
207208 let should_panic;
208209 let ignore;
209210 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
224213 } else {
225214 return event;
226- }
227-
228- let explicit_edition = edition. is_some ( ) ;
229- let edition = edition. unwrap_or ( self . edition ) ;
215+ } ;
230216
231217 let mut origtext = String :: new ( ) ;
232218 for event in & mut self . inner {
@@ -241,6 +227,35 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
241227 let lines = origtext. lines ( ) . filter_map ( |l| map_line ( l) . for_html ( ) ) ;
242228 let text = lines. collect :: < Vec < Cow < ' _ , str > > > ( ) . join ( "\n " ) ;
243229
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+
244259 let playground_button = self . playground . as_ref ( ) . and_then ( |playground| {
245260 let krate = & playground. crate_name ;
246261 let url = & playground. url ;
0 commit comments