#web #utility #command-line-tool #text #cli

bin+lib up2code

up2code is a tool to check code listings in Markdown files against a GitHub repository

4 releases (breaking)

0.4.0 Oct 28, 2024
0.3.0 Oct 23, 2024
0.2.0 Oct 23, 2024
0.1.0 Oct 18, 2024

#1565 in Command line utilities

Download history 138/week @ 2024-10-14 261/week @ 2024-10-21 146/week @ 2024-10-28

545 downloads per month

MIT/Apache

18KB
116 lines

Crate Docs CI Audit Maintenance

up2code

up2code is a tool for checking code listings in Markdown files, to make sure they're up to date with, and in sync with, canonical versions stored in a GitHub repo.

Installation

cargo install up2code

Usage

Run:

up2code book/*.md

up2code reads all the Markdown files you specify, looking for what it considers a “listing”: a fenced code block immediately followed by a web link. For example:

```rust
fn main() {
    println!("Hello, world!")
}
```
[Listing `hello/1`](https://github.com/bitfield/example/blob/src/main.rs))

It will try to fetch the raw code page from the specified URL (appending "?raw=true"), reporting any errors. If the fetch succeeds, it will check that the Markdown listing is an exact substring of the GitHub listing, reporting any mismatch as a unified diff:

tests/data/test.md: Listing `counter_2`
@@ -6,8 +13,8 @@

     #[test]
     fn count_lines_fn_counts_lines_in_input() {
-        let input = io::Cursor::new("line 1\nline2\n");
+        let input = io::Cursor::new("line 1\nline 2\n");
         let lines = count_lines(input);
-        assert_eq!(2, lines);
+        assert_eq!(lines, 2);
     }
 }

Dependencies

~7–18MB
~245K SLoC