From e23435b30eea53de78a361092c8f386927443a68 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 01:32:38 +0100 Subject: [PATCH 1/2] Add usage details to README --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f0a05fb5..219862f9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,48 @@ # mdtablefix -This is a generated project using [Copier](https://copier.readthedocs.io/). +`mdtablefix` reflows Markdown tables so that each column has a uniform width. +It ignores fenced code blocks and respects escaped pipes (`\|`), +making it safe for mixed content. -A tool to reflow Markdown tables while preserving other document content. +## Installation + +```bash +cargo install mdtablefix +``` + +or clone the repository and build from source: + +```bash +cargo install --path . +``` + +## Command-line usage + +```bash +mdtablefix [--in-place] [FILE...] +``` + +- With file paths provided, the corrected tables are printed to stdout. +Use `--in-place` to overwrite files. +- If no files are supplied, input is read from stdin and results are written to stdout. + +## Library usage + +The crate exposes helper functions so you can integrate the table reflow logic +in your own project. + +```rust +use mdtablefix::{process_stream, rewrite}; +``` + +- `process_stream(&[String]) -> Vec` rewrites tables in memory. +- `rewrite(Path)` updates a Markdown file on disk. + +## Testing + +See `docs/rust-testing-with-rstest-fixtures.md` for notes on how the test suite +is organised using the [`rstest`](https://crates.io/crates/rstest) crate. + +## License + +This project is licensed under the ISC license. From f528a02d4709d966db23347127bd979b847aefea Mon Sep 17 00:00:00 2001 From: Leynos Date: Sat, 14 Jun 2025 02:33:41 +0100 Subject: [PATCH 2/2] Improve README --- README.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 219862f9..7de01a0b 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,27 @@ mdtablefix [--in-place] [FILE...] ``` - With file paths provided, the corrected tables are printed to stdout. -Use `--in-place` to overwrite files. +- Use `--in-place` to overwrite files. - If no files are supplied, input is read from stdin and results are written to stdout. +### Example + +Before: + +```markdown +| A|B | C | +|---|--|---| +|1|22|333 | +``` + +After running `mdtablefix`: + +```markdown +| A | B | C | +| --- | --- | --- | +| 1 | 22 | 333 | +``` + ## Library usage The crate exposes helper functions so you can integrate the table reflow logic @@ -33,10 +51,19 @@ in your own project. ```rust use mdtablefix::{process_stream, rewrite}; +use std::path::Path; + +fn main() -> std::io::Result<()> { + let lines = vec!["|A|B|".to_string(), "|1|2|".to_string()]; + let fixed = process_stream(&lines); + println!("{}", fixed.join("\n")); + rewrite(Path::new("table.md"))?; + Ok(()) +} ``` - `process_stream(&[String]) -> Vec` rewrites tables in memory. -- `rewrite(Path)` updates a Markdown file on disk. +- `rewrite(&Path) -> std::io::Result<()>` updates a Markdown file on disk. ## Testing @@ -46,3 +73,4 @@ is organised using the [`rstest`](https://crates.io/crates/rstest) crate. ## License This project is licensed under the ISC license. +See the [LICENSE](LICENSE) file for details.