Markdown Table Formatter
CLI
$ cat table.md
w | x | y | z
---|:---|---:|:---:
1 | 1 | 1 | 1
2 | 4 | 16 | 256
3 | 9 | 81 | 6561
4 | 16 | 256 | 65536
$ mtf table.md
| w | x | y | z |
|----|:---|----:|:-----:|
| 1 | 1 | 1 | 1 |
| 2 | 4 | 16 | 256 |
| 3 | 9 | 81 | 6561 |
| 4 | 16 | 256 | 65536 |
Text Editor
- Use a text editor (Vim, Neovim, Helix Editor, ...)
- Select Markdown table content in a file
(in Helix Editor type
␛x then x repeatedly, or type ␛v then hjkl or arrows)
- Pass it as input to
mtf
(in Helix Editor type |mtf⏎)
mtf formats the table content
Library
let input = "\
w | x | y | z
---|:---|---:|:---:
1 | 1 | 1 | 1
2 | 4 | 16 | 256
3 | 9 | 81 | 6561
4 | 16 | 256 | 65536
";
let output = "\
| w | x | y | z |
|----|:---|----:|:-----:|
| 1 | 1 | 1 | 1 |
| 2 | 4 | 16 | 256 |
| 3 | 9 | 81 | 6561 |
| 4 | 16 | 256 | 65536 |
";
assert_eq!(mtf::process(input).unwrap(), output);