Home

Awesome

mdsf

Format markdown code snippets using your favorite code formatters.

<a href="https://crates.io/crates/mdsf"><img src="https://img.shields.io/crates/v/mdsf.svg"></a> <a href="https://github.com/hougesen/mdsf/actions/workflows/validate.yml"><img src="https://github.com/hougesen/mdsf/actions/workflows/validate.yml/badge.svg"></a>

<!-- <a href="https://codecov.io/gh/hougesen/mdsf"><img src="https://codecov.io/gh/hougesen/mdsf/branch/main/graph/badge.svg"/></a> --> <!-- START_SECTION:base-command-help -->
mdsf 0.2.3
Format markdown code snippets using your favorite code formatters
Mads Hougesen <mads@mhouge.dk>

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
<!-- END_SECTION:base-command-help -->

Installation

The latest version of mdsf can be downloaded directly from github.com/hougesen/mdsf/releases.

Cargo

Install using the published crate:

cargo install mdsf --locked

or directly from source:

git clone git@github.com:hougesen/mdsf.git

cargo install --path ./mdsf --bin mdsf

Usage

mdsf format <NAME_OF_FOLDER_OR_FOLDER>
<!-- START_SECTION:format-command-help -->
Run formatters on input files

Usage: mdsf format [OPTIONS] <PATH>

Arguments:
  <PATH>  Path to file or directory

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
<!-- END_SECTION:format-command-help -->

Verify code is formatted

mdsf verify <NAME_OF_FOLDER_OR_FOLDER>
<!-- START_SECTION:verify-command-help -->
Verify files are formatted

Usage: mdsf verify [OPTIONS] <PATH>

Arguments:
  <PATH>  Path to file or directory

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
<!-- END_SECTION:verify-command-help -->

Configuration

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.

{
  // 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"]
}

Supported tools

[!NOTE] mdsf is not a package manager.

Only tools that are already installed will be used.

<!-- START_SECTION:supported-tools -->

mdsf currently supports 174 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

FormatterDescription
alejandrahttps://github.com/kamadorueda/alejandra
amebahttps://github.com/crystal-ameba/ameba
asmfmthttps://github.com/klauspost/asmfmt
astylehttps://astyle.sourceforge.net
auto-optionalhttps://pypi.org/project/auto-optional/
autocorrecthttps://github.com/huacnlee/autocorrect
autoflakehttps://github.com/pycqa/autoflake
autopep8https://pypi.org/project/autopep8/
beautyshhttps://pypi.org/project/beautysh/
bicep_formathttps://github.com/Azure/bicep
biomehttps://biomejs.dev
biome_checkhttps://biomejs.dev
biome_linthttps://biomejs.dev
blackhttps://github.com/psf/black
blade-formatterhttps://github.com/shufo/blade-formatter
bluehttps://blue.readthedocs.io/en/latest/
bpfmthttps://source.android.com/docs/setup/reference/androidbp
brittanyhttps://github.com/lspitzner/brittany
bsfmthttps://github.com/rokucommunity/brighterscript-formatter
bufhttps://buf.build/docs/reference/cli/buf/format
buildifierhttps://github.com/bazelbuild/buildtools
cabal_formathttps://www.haskell.org/cabal/
caramel_fmthttps://caramel.run
clang-formathttps://docs.kernel.org/process/clang-format.html
clang-tidyhttps://clang.llvm.org/extra/clang-tidy
cljstylehttps://github.com/greglook/cljstyle
codespellhttps://github.com/codespell-project/codespell
crlfmthttps://github.com/cockroachdb/crlfmt
crystal_formathttps://crystal-lang.org/
csharpierhttps://csharpier.com/
css-beautifyhttps://github.com/beautifier/js-beautify
csscombhttps://github.com/csscomb/csscomb.js
d2https://d2lang.com/
dart_fixhttps://dart.dev/tools/dart-fix
dart_formathttps://dart.dev/tools/dart-format
dcm_fixhttps://dcm.dev/docs/cli/fix/
dcm_formathttps://dcm.dev/docs/cli/format/
deno_fmthttps://docs.deno.com/runtime/manual/tools/formatter
deno_linthttps://docs.deno.com/runtime/manual/tools/linter
dfmthttps://github.com/dlang-community/dfmt
dhallhttps://dhall-lang.org/
djlinthttps://www.djlint.com/
docformatterhttps://pypi.org/project/docformatter/
docstrfmthttps://pypi.org/project/docstrfmt/
dotenv-linterhttps://github.com/dotenv-linter/dotenv-linter
dprinthttps://dprint.dev
easy-cofing-standardhttps://github.com/easy-coding-standard/easy-coding-standard
efmthttps://github.com/sile/efmt
elm-formathttps://github.com/avh4/elm-format
erb-formatterhttps://github.com/nebulab/erb-formatter
erlfmthttps://github.com/WhatsApp/erlfmt
eslinthttps://eslint.org
fantomashttps://github.com/fsprojects/fantomas
findenthttps://pypi.org/project/findent/
fish_indenthttps://fishshell.com/docs/current/cmds/fish_indent.html
fixjsonhttps://github.com/rhysd/fixjson
floskellhttps://github.com/ennocramer/floskell
fnlfmthttps://git.sr.ht/~technomancy/fnlfmt
forge_fmthttps://docs.rs/forge-fmt/latest/forge_fmt/
fourmoluhttps://hackage.haskell.org/package/fourmolu
fprettifyhttps://github.com/fortran-lang/fprettify
gcihttps://github.com/daixiang0/gci
gdformathttps://github.com/scony/godot-gdscript-toolkit
gersemihttps://github.com/blankspruce/gersemi
gleam_formathttps://gleam.run/
gluon_fmthttps://github.com/gluon-lang/gluon
gofmthttps://pkg.go.dev/cmd/gofmt
gofumpthttps://github.com/mvdan/gofumpt
goimportshttps://pkg.go.dev/golang.org/x/tools/cmd/goimports
goimports-reviserhttps://github.com/incu6us/goimports-reviser
golineshttps://github.com/segmentio/golines
google-java-formathttps://github.com/google/google-java-format
grain_formathttps://grain-lang.org
haml-linthttps://github.com/sds/haml-lint
hfmthttps://github.com/danstiner/hfmt
hindenthttps://hackage.haskell.org/package/hindent
html-beautifyhttps://github.com/beautifier/js-beautify
htmlbeautifierhttps://github.com/threedaymonk/htmlbeautifier
imba_fmthttps://github.com/imba/imba
isorthttps://pycqa.github.io/isort/
jokerhttps://github.com/candid82/joker
js-beautifyhttps://github.com/beautifier/js-beautify
jsona_formathttps://github.com/jsona/jsona
jsonnetfmthttps://jsonnet.org/learning/tools.html
juliaformatter.jlhttps://github.com/domluna/JuliaFormatter.jl
just_fmthttps://github.com/casey/just
kcl_fmthttps://www.kcl-lang.io/docs/tools/cli/kcl/fmt
kdlfmthttps://github.com/hougesen/kdlfmt
ktfmthttps://github.com/facebook/ktfmt
ktlinthttps://github.com/pinterest/ktlint
leptosfmthttps://github.com/bram209/leptosfmt
liquidsoap-prettierhttps://github.com/savonet/liquidsoap-prettier
luaformatterhttps://github.com/Koihik/LuaFormatter
markdownlinthttps://github.com/davidanson/markdownlint
markuplinthttps://markuplint.dev
mdformathttps://github.com/executablebooks/mdformat
misspellhttps://github.com/client9/misspell/
mix_formathttps://hexdocs.pm/mix/main/Mix.Tasks.Format.html
nickel_formathttps://nickel-lang.org
nimprettyhttps://github.com/nim-lang/nim
nixfmthttps://github.com/serokell/nixfmt
nixpkgs-fmthttps://github.com/nix-community/nixpkgs-fmt
nphhttps://github.com/arnetheduck/nph
npm-groovy-linthttps://github.com/nvuillam/npm-groovy-lint
ocamlformathttps://github.com/ocaml-ppx/ocamlformat
ocp-indenthttps://github.com/OCamlPro/ocp-indent
ormoluhttps://hackage.haskell.org/package/ormolu
oxlinthttps://oxc.rs
packer_fmthttps://developer.hashicorp.com/packer/docs/commands/fmt
perltidyhttps://github.com/perltidy/perltidy
pg_formathttps://github.com/darold/pgFormatter
php-cs-fixerhttps://github.com/PHP-CS-Fixer/PHP-CS-Fixer
phpcbfhttps://phpqa.io/projects/phpcbf.html
phpinsightshttps://phpinsights.com/
pinthttps://github.com/laravel/pint
prettierhttps://github.com/prettier/prettier
pretty-phphttps://github.com/lkrms/pretty-php
prismahttps://prisma.io/
puppet-linthttps://github.com/puppetlabs/puppet-lint
purs-tidyhttps://github.com/natefaubion/purescript-tidy
pyclnhttps://github.com/hadialqattan/pycln
pyinkhttps://github.com/google/pyink
qmlfmthttps://github.com/jesperhh/qmlfmt
raco_fmthttps://docs.racket-lang.org/fmt/
refmthttps://reasonml.github.io/docs/en/
rescript_formathttps://rescript-lang.org/
roc_formathttps://github.com/roc-lang/roc
rstfmthttps://github.com/dzhu/rstfmt
rubocophttps://github.com/rubocop/rubocop
rubyfmthttps://github.com/fables-tales/rubyfmt
ruffhttps://docs.astral.sh/ruff/formatter/
ruff_checkhttps://docs.astral.sh/ruff/linter/
rufohttps://github.com/ruby-formatter/rufo
rune_fmthttps://github.com/rune-rs/rune
rustfmthttps://github.com/rust-lang/rustfmt
rustywindhttps://github.com/avencera/rustywind
scalafmthttps://github.com/scalameta/scalafmt
shfmthttps://github.com/mvdan/sh
sleekhttps://github.com/nrempel/sleek
smlfmthttps://github.com/shwestrick/smlfmt
snakefmthttps://github.com/snakemake/snakefmt
sql-formatterhttps://github.com/sql-formatter-org/sql-formatter
sqlfluffhttps://github.com/sqlfluff/sqlfluff
sqlfmthttps://sqlfmt.com
standardjshttps://standardjs.com/
standardrbhttps://github.com/standardrb/standard
stylefmthttps://github.com/matype/stylefmt
stylelinthttps://github.com/stylelint/stylelint
stylish-haskellhttps://github.com/haskell/stylish-haskell
styluahttps://github.com/JohnnyMorganz/StyLua
swift-formathttps://github.com/apple/swift-format
swiftformathttps://github.com/nicklockwood/SwiftFormat
taplohttps://github.com/tamasfe/taplo
templhttps://templ.guide
terraform_fmthttps://www.terraform.io/docs/cli/commands/fmt.html
tlinthttps://github.com/tighten/tlint
tofu_fmthttps://opentofu.org/docs/cli/commands/fmt/
topiaryhttps://github.com/tweag/topiary
ts-standardhttps://github.com/standard/ts-standard
twig-cs-fixerhttps://github.com/VincentLanglet/Twig-CS-Fixer
typoshttps://github.com/crate-ci/typos
uiua_fmthttps://github.com/uiua-lang/uiua
usorthttps://github.com/facebook/usort
veryl_fmthttps://github.com/veryl-lang/veryl
vlang_fmthttps://vlang.io
xmlformathttps://github.com/pamoller/xmlformatter
xmllinthttp://xmlsoft.org/xmllint.html
xohttp://github.com/xojs/xo
yamlfixhttps://github.com/lyz-code/yamlfix
yamlfmthttps://github.com/google/yamlfmt
yapfhttps://github.com/google/yapf
yew-fmthttps://github.com/its-the-shrimp/yew-fmt
zigfmthttps://ziglang.org/
zprinthttps://github.com/kkinnear/zprint
<!-- END_SECTION:supported-tools -->

Shell completions

Shell completions can be generated using mdsf completions <SHELL>.

<!-- START_SECTION:completions-command-help -->
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
<!-- END_SECTION:completions-command-help -->

Bash

Add the following to your .bashrc.

eval "$(mdsf completions bash)"

Bash

Add the following to your .zshrc.

eval "$(mdsf completions zsh)"

Fish

Add the following to ~/.config/fish/config.fish.

mdsf completions fish | source

PowerShell

Add the following to your PowerShell configuration (Can be found by running $PROFILE).

Invoke-Expression (&mdsf completions powershell)

Elvish

Add the following to ~/.elvish/rc.elv.

eval (mdsf completions elvish)

Acknowledgement

mdsf was inspired by the amazing neovim formatting plugin conform.nvim.

Alternatives to mdsf