@@ -8,7 +8,7 @@ use clippy_config::ClippyConfiguration;
88use clippy_lints:: LintInfo ;
99use clippy_lints:: declared_lints:: LINTS ;
1010use 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} ;
1212use rinja:: Template ;
1313use rinja:: filters:: Safe ;
1414use serde:: Deserialize ;
@@ -394,11 +394,27 @@ struct Renderer<'a> {
394394 lints : & ' a Vec < LintMetadata > ,
395395}
396396
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. split ( ',' ) . any ( |lang| [ "" , "rust" , "ignore" , "should_panic" , "no_run" , "compile_fail" ] . contains ( & lang) ) {
406+ return Some ( Event :: Start ( Tag :: CodeBlock ( CodeBlockKind :: Fenced ( CowStr :: Borrowed ( "rust" ) ) ) ) ) ;
407+ }
408+ }
409+ Some ( event)
410+ }
411+ }
412+
397413impl Renderer < ' _ > {
398414 fn markdown ( input : & str ) -> Safe < String > {
399415 let parser = Parser :: new_ext ( input, Options :: all ( ) ) ;
400416 let mut html_output = String :: new ( ) ;
401- html:: push_html ( & mut html_output, parser) ;
417+ html:: push_html ( & mut html_output, CodeBlockModifier ( parser) ) ;
402418 // Oh deer, what a hack :O
403419 Safe ( html_output. replace ( "<table" , "<table class=\" table\" " ) )
404420 }
0 commit comments