webern / cargo-readme

Generate README.md from docstrings
Other
360 stars 57 forks source link

Add every rustdoc language annotation #83

Open ErikBot42 opened 1 year ago

ErikBot42 commented 1 year ago

This adds support for every language annotation that rustdoc recognizes

should_panic   
should-panic   <- new  
shouldpanic    <- new 
no_run         
no-run         <- new      
norun          <- new
ignore         
ignore-.*      <- new
rust           
test_harness   <- new  
test-harness   <- new  
testharness    <- new 
compile_fail   <- new
compile-fail   <- new
compilefail    <- new
edition....    <- new
E....          <- new    

The only change that was needed was to modify the regex that recognized if a code block is rust code

The new regex works on this input:

test file

//! should_panic:
//! ```should_panic
//! let a = 3;
//! ```
//! should-panic:
//! ```should-panic
//! let a = 3;
//! ```
//! shouldpanic:
//! ```shouldpanic
//! let a = 3;
//! ```
//! no_run:
//! ```no_run
//! let a = 3;
//! ```
//! no-run:
//! ```no-run
//! let a = 3;
//! ```
//! norun:
//! ```norun
//! let a = 3;
//! ```
//! ignore:
//! ```ignore
//! let a = 3;
//! ```
//! ignore-on-some-hardware:
//! ```ignore-on-some-hardware
//! let a = 3;
//! ```
//! rust:
//! ```rust
//! let a = 3;
//! ```
//! test_harness:
//! ```test_harness
//! let a = 3;
//! ```
//! test-harness:
//! ```test-harness
//! let a = 3;
//! ```
//! testharness:
//! ```testharness
//! let a = 3;
//! ```
//! compile_fail:
//! ```compile_fail
//! let a = 3;
//! ```
//! compile-fail:
//! ```compile-fail
//! let a = 3;
//! ```
//! compilefail:
//! ```compilefail
//! let a = 3;
//! ```
//! edition2015
//! ```edition2015
//! let a = 3;
//! ```
//! E1234:
//! ```E1234
//! let a = 3;
//! ```

output

should_panic:

let a = 3;

should-panic:

let a = 3;

shouldpanic:

let a = 3;

no_run:

let a = 3;

no-run:

let a = 3;

norun:

let a = 3;

ignore:

let a = 3;

ignore-on-some-hardware:

let a = 3;

rust:

let a = 3;

test_harness:

let a = 3;

test-harness:

let a = 3;

testharness:

let a = 3;

compile_fail:

let a = 3;

compile-fail:

let a = 3;

compilefail:

let a = 3;

edition2015

let a = 3;

E1234:

let a = 3;