@@ -8,7 +8,7 @@ use clippy_config::ClippyConfiguration;
8
8
use clippy_lints:: LintInfo ;
9
9
use clippy_lints:: declared_lints:: LINTS ;
10
10
use clippy_lints:: deprecated_lints:: { DEPRECATED , DEPRECATED_VERSION , RENAMED } ;
11
- use pulldown_cmark:: { Options , Parser , html} ;
11
+ use pulldown_cmark:: { CodeBlockKind , CowStr , Event , Options , Parser , Tag , html} ;
12
12
use rinja:: Template ;
13
13
use rinja:: filters:: Safe ;
14
14
use serde:: Deserialize ;
@@ -394,11 +394,32 @@ struct Renderer<'a> {
394
394
lints : & ' a Vec < LintMetadata > ,
395
395
}
396
396
397
+ struct CodeBlockModifier < I > ( I ) ;
398
+
399
+ impl < ' a , I : Iterator < Item = Event < ' a > > > Iterator for CodeBlockModifier < I > {
400
+ type Item = Event < ' a > ;
401
+
402
+ fn next ( & mut self ) -> Option < Self :: Item > {
403
+ let Some ( event) = self . 0 . next ( ) else { return None } ;
404
+ if let Event :: Start ( Tag :: CodeBlock ( CodeBlockKind :: Fenced ( ref lang) ) ) = event {
405
+ if lang
406
+ . split ( ',' )
407
+ . any ( |lang| [ "" , "rust" , "ignore" , "should_panic" , "no_run" , "compile_fail" ] . contains ( & lang) )
408
+ {
409
+ return Some ( Event :: Start ( Tag :: CodeBlock ( CodeBlockKind :: Fenced ( CowStr :: Borrowed (
410
+ "rust" ,
411
+ ) ) ) ) ) ;
412
+ }
413
+ }
414
+ Some ( event)
415
+ }
416
+ }
417
+
397
418
impl Renderer < ' _ > {
398
419
fn markdown ( input : & str ) -> Safe < String > {
399
420
let parser = Parser :: new_ext ( input, Options :: all ( ) ) ;
400
421
let mut html_output = String :: new ( ) ;
401
- html:: push_html ( & mut html_output, parser) ;
422
+ html:: push_html ( & mut html_output, CodeBlockModifier ( parser) ) ;
402
423
// Oh deer, what a hack :O
403
424
Safe ( html_output. replace ( "<table" , "<table class=\" table\" " ) )
404
425
}
0 commit comments