Format markdown code snippets using your favorite code formatters.
mdsf 0.2.7
Format markdown code snippets using your favorite code formatters
Mads Hougesen <[email protected]>
Usage: mdsf <COMMAND>
Commands:
format Run formatters on input files
verify Verify files are formatted
init Create a new mdsf config
completions Generate shell completion
cache-prune Remove old caches
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
The latest version of mdsf
can be downloaded directly from github.com/hougesen/mdsf/releases.
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/hougesen/mdsf/releases/latest/download/mdsf-installer.sh | sh
powershell -ExecutionPolicy ByPass -c "irm https://github.com/hougesen/mdsf/releases/latest/download/mdsf-installer.ps1 | iex"
Install using the published crate:
cargo install mdsf --locked
or directly from source:
git clone [email protected]:hougesen/mdsf.git
cargo install --path ./mdsf --bin mdsf
If you do not have Cargo installed, you need to install it first.
You can install mdsf using npm:
npm install -g mdsf-cli
mdsf-cli format .
or run it directly using npx:
npx mdsf-cli format .
brew install hougesen/tap/mdsf
mdsf format file.md
Run formatters on input files
Usage: mdsf format [OPTIONS] [INPUT]...
Arguments:
[INPUT]... Path to files and/or directories
Options:
--config <CONFIG> Path to config
--debug Log stdout and stderr of formatters
--log-level <LOG_LEVEL> [possible values: trace, debug, info, warn, error, off]
--threads <THREADS> Amount of threads to use. Defaults to 0 (auto)
--cache Only format changed codeblocks
-h, --help Print help
-V, --version Print version
mdsf verify docs/
Verify files are formatted
Usage: mdsf verify [OPTIONS] [INPUT]...
Arguments:
[INPUT]... Path to files and/or directories
Options:
--config <CONFIG> Path to config
--debug Log stdout and stderr of formatters
--log-level <LOG_LEVEL> [possible values: trace, debug, info, warn, error, off]
--threads <THREADS> Amount of threads to use. Defaults to 0 (auto)
-h, --help Print help
-V, --version Print version
The default configuration of mdsf
aims to as sane as possible. For that reason the default formatter for each language is the one most people have installed.
If you are interested in customizing which formatter is run, you can create a new mdsf
configuration file by running
mdsf init
mdsf
supports running multiple formatters on the save code snippet.
{
"languages": {
// Only run `ruff` on Python snippets,
"python": "ruff",
// Run `usort` on file and then `black`
"python": ["usort", "black"],
// Run `usort`, if that fails run `isort`, finally run `black`
"python": [["usort", "isort"], "black"],
// Formatters listed under "*" will be run on any snippet.
"*": ["typos"],
// Formatters listed under "_" will only be run when there is not formatter configured for the file type OR globally ("*").
"_": "prettier"
}
}
[!NOTE] mdsf is not a package manager.
Only tools that are already installed will be used.
mdsf
currently supports 187 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
Shell completions can be generated using mdsf completions <SHELL>
.
Generate shell completion
Usage: mdsf completions <SHELL>
Arguments:
<SHELL> [possible values: bash, elvish, fish, powershell, zsh]
Options:
-h, --help Print help
-V, --version Print version
Add the following to your .bashrc
.
eval "$(mdsf completions bash)"
Add the following to your .zshrc
.
eval "$(mdsf completions zsh)"
Add the following to ~/.config/fish/config.fish
.
mdsf completions fish | source
Add the following to your PowerShell configuration (Can be found by running $PROFILE
).
Invoke-Expression (&mdsf completions powershell)
Add the following to ~/.elvish/rc.elv
.
eval (mdsf completions elvish)
mdsf was inspired by the amazing neovim formatting plugin conform.nvim.
injected
mode.