@@ -63,7 +63,7 @@ fn build_page(
6363fn postprocess < ' a > ( content : & ' a AstNode < ' a > ) {
6464 lower_headings ( content) ;
6565 rewrite_md_links ( content) ;
66- strip_hidden_code ( content) ;
66+ strip_rustdoc_idioms ( content) ;
6767}
6868
6969fn lower_headings < ' a > ( root : & ' a AstNode < ' a > ) {
@@ -87,25 +87,24 @@ fn rewrite_md_links<'a>(root: &'a AstNode<'a>) {
8787 }
8888}
8989
90- fn strip_hidden_code < ' a > ( root : & ' a AstNode < ' a > ) {
90+ fn strip_rustdoc_idioms < ' a > ( root : & ' a AstNode < ' a > ) {
9191 for node in root. descendants ( ) {
9292 let mut data = node. data . borrow_mut ( ) ;
9393 if let NodeValue :: CodeBlock ( NodeCodeBlock { info, literal, .. } ) = & mut data. value {
94- if info. split ( ',' ) . map ( str:: trim) . all ( |lang| lang != "rust" ) {
95- continue ;
94+ // Rustdoc uses commas, but CommonMark uses spaces
95+ * info = info. replace ( "," , " " ) ;
96+
97+ // Rustdoc uses "#" to represent hidden setup code
98+ if info. split_whitespace ( ) . next ( ) == Some ( "rust" ) {
99+ * literal = literal
100+ . split ( '\n' )
101+ . filter ( |line| {
102+ let line = line. trim ( ) ;
103+ line != "#" && !line. starts_with ( "# " )
104+ } )
105+ . collect :: < Vec < _ > > ( )
106+ . join ( "\n " ) ;
96107 }
97- * literal = strip_hidden_code_inner ( literal) ;
98108 }
99109 }
100110}
101-
102- fn strip_hidden_code_inner ( literal : & str ) -> String {
103- let lines = literal
104- . split ( '\n' )
105- . filter ( |line| {
106- let line = line. trim ( ) ;
107- line != "#" && !line. starts_with ( "# " )
108- } )
109- . collect :: < Vec < _ > > ( ) ;
110- lines. join ( "\n " )
111- }
0 commit comments