Format, and lint, markdown code snippets using your favorite tools
npm install mdsf-cliFormat, and lint, markdown code snippets using your favorite tools.
- Table of contents
- Installation
- Linux & MacOS
- Windows
- Cargo
- npm/npx
- Homebrew
- Conda
- Usage
- Formatting code
- Caching formatting results
- Removing old caches
- Verifying code
- GitHub Action
- Visual Studio Code
- Vim / NeoVim
- conform.nvim
- treefmt
- pre-commit
- Configuration
- Language aliases
- Newlines
- Custom tools and commands
- Tools
- Commands
- Shell completions
- Bash
- Zsh
- Fish
- PowerShell
- Elvish
- Nushell
- Rust MSRV
- Acknowledgement
- Alternatives to mdsf
The latest version of mdsf can be downloaded directly from github.com/hougesen/mdsf/releases.
``shell`
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/hougesen/mdsf/releases/latest/download/mdsf-installer.sh | sh
`powershell`
powershell -ExecutionPolicy ByPass -c "irm https://github.com/hougesen/mdsf/releases/latest/download/mdsf-installer.ps1 | iex"
Install using the published crate:
`shell`
cargo install mdsf --locked
or directly from source:
`shell
git clone git@github.com: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:
`shell
npm install -g mdsf-cli
mdsf format .
`
or run it directly using npx:
`shell`
npx mdsf-cli format .
`shell`
brew install hougesen/tap/mdsf
An _unofficial_ (and unsupported) Conda package can be found at https://anaconda.org/conda-forge/mdsf.
`shell`
conda install conda-forge::mdsf
`
mdsf 0.11.1
Format, and lint, markdown code snippets using your favorite tools
Mads Hougesen
Usage: mdsf [OPTIONS]
Commands:
format Run tools on input files
verify Verify files are formatted
init Create a new mdsf config
completions Generate shell completion
cache-prune Remove caches
help Print this message or the help of the given subcommand(s)
Options:
--log-level
-h, --help Print help
-V, --version Print version
`
The format command, as the name implies, is used to format documents.
`shell`
mdsf format file.md
`
Run tools on input files
Usage: mdsf format [OPTIONS] [INPUT]...
Arguments:
[INPUT]...
Path to files and/or directories
Options:
--stdin
Read input from stdin and write output to stdout
--config
Path to config file
--debug
Log stdout and stderr of formatters
--threads
Amount of threads to use.
Defaults to 0 (auto).
--cache
Cache results
--log-level
[possible values: trace, debug, info, warn, error, off]
--timeout
Tool timeout in seconds.
Defaults to no timeout.
--on-missing-language-definition
What to do when a codeblock language has no tools defined
[possible values: ignore, fail, fail-fast]
--on-missing-tool-binary
What to do when the binary of a tool cannot be found
[possible values: ignore, fail, fail-fast]
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
`
#### Caching formatting results
To speed formatting caching can be enabled by supplying the format command with the --cache argument.
`shell`
mdsf format --cache docs/
##### Removing old caches
Old caches can be removed by running the mdsf cache-prune command.
`
Remove caches
Usage: mdsf cache-prune [OPTIONS]
Options:
--log-level
-h, --help Print help
-V, --version Print version
`
You can verify that the document is formatted using the mdsf verify command.
`shell`
mdsf verify docs/
`
Verify files are formatted
Usage: mdsf verify [OPTIONS] [INPUT]...
Arguments:
[INPUT]...
Path to files and/or directories
Options:
--stdin
Read input from stdin and write output to stdout
--config
Path to config file
--debug
Log stdout and stderr of formatters
--threads
Amount of threads to use.
Defaults to 0 (auto).
--timeout
Tool timeout in seconds.
Defaults to no timeout.
--log-level
[possible values: trace, debug, info, warn, error, off]
--on-missing-language-definition
What to do when a codeblock language has no tools defined
[possible values: ignore, fail, fail-fast]
--on-missing-tool-binary
What to do when the binary of a tool cannot be found
[possible values: ignore, fail, fail-fast]
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
`
There are a lot of different ways to run mdsf using GitHub actions.
The easiest way, in my opinion, is to use the official GitHub action to install mdsf.
After that you can run the binary like you would in your terminal.
> \[!NOTE\]
> mdsf is not a package manager.
>
> You must also install the tools you wish to use in your GitHub action.
`yaml
name: mdsf
on: push
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install mdsf
uses: hougesen/mdsf@main
- name: Run mdsf
run: mdsf format --log-level warn .
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
message: "style: formatted markdown code blocks"
`


mdsf can be run using the VSCode extension.
> \[!NOTE\]
> The mdsf VS Code extension does currently not support installing mdsf.
> Which means mdsf must be installed using other means.
#### conform.nvim
conform.nvim has native support for running mdsf.
`lua
local conform = require("conform")
conform.setup({
formatters_by_ft = {
markdown = { "mdsf" },
-- ...
},
-- ...
})
`
Add the following to your treefmt.toml to run mdsf using treefmt.
`tomltreefmt.toml
[formatter.mdsf]
command = "mdsf"
options = ["format"]
includes = ["*.md"]
`
See pre-commit for instructions
Sample .pre-commit-config.yaml:
`yaml`
repos:
- repo: https://github.com/hougesen/mdsf
rev: main
hooks:
- id: mdsf-format
The default configuration of mdsf aims to as simple 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.
`
Create a new mdsf config
Usage: mdsf init [OPTIONS]
Options:
--force Create config even if one already exists in current directory
--log-level
-h, --help Print help
-V, --version Print version
`
mdsf supports running multiple formatters on the code snippet.
`jsonruff
{
"languages": {
// Only run on Python snippets,usort
"python": "ruff:format",
// Run on file and then blackusort
"python": ["usort", "black"],
// Run , 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"
}
}
`
Multiple languages can easily be mapped to the same tools using the language_aliases option.
`json`
{
"language_aliases": {
"language": "is_alias_of"
}
}
In the example below bash and zsh would use the tools defined under languages.shell.
`json`
{
"languages": {
"shell": "shfmt"
},
"language_aliases": {
"bash": "shell",
"zsh": "shell"
}
}
By default LF (\n) is used for newlines.
That can be changed by specifying the newline config option.
`json`
{
"newline": "lf" // "lf" | "cr" | "crlf"
}
Custom commands can be defined in the mdsf.json file.
When defining the arguments the variable $PATH will automatically be replaced with the file path.
`json`
{
"languages": {
"rust": {
"binary": "rustfmt",
"arguments": ["--edition", "2018", "$PATH"],
"stdin": false
}
}
}
> \[!NOTE\]
> mdsf is not a package manager.
>
> Only tools that are already installed will be used.
mdsf currently supports 335 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
| Name | Description | Categories | Languages |
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| actionlint | Static checker for GitHub Actions workflow files | linter | yaml |formatter
| air | R formatter | | r |formatter
| alejandra | The Uncompromising Nix Code Formatter | | nix |spell-check
| alex | Catch insensitive, inconsiderate writing | | markdown |linter
| ameba | A static code analysis tool for Crystal | | crystal |linter
| ansible-lint | ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you | | ansible |linter
| api-linter | A linter for APIs defined in protocol buffers | | protobuf |formatter
| asmfmt | Go Assembler Formatter | | go |formatter
| astyle | A Free, Fast, and Small Automatic Formatter for C, C++, C++/CLI, Objective-C, C#, and Java Source Code | | c#, c++, c, java, objective-c |formatter
| atlas | Manage your database schema as code | | hcl |formatter
| auto-optional | Makes typed arguments Optional when the default argument is None | | python |spell-check
| autocorrect | A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuations between CJK (Chinese, Japanese, Korean) | | |linter
| autoflake | Removes unused imports and unused variables as reported by pyflakes | | python |formatter
| autopep8 | A tool that automatically formats Python code to conform to the PEP 8 style guide | | python |formatter
| bashate | Code style enforcement for bash programs | | bash |formatter
| beancount-black | Opinionated code formatter, just like Python's black code formatter but for Beancount | | beancount |formatter
| beautysh | A Bash beautifier for the masses | | bash, shell |formatter
| bibtex-tidy | Cleaner and Formatter for BibTeX files | | bibtex |formatter
| bicep | Bicep is a declarative language for describing and deploying Azure resources | | bicep |formatter
| biome | A toolchain for web projects | , linter | javascript, json, typescript, vue |formatter
| black | The uncompromising Python code formatter | | python |formatter
| blade-formatter | An opinionated blade template formatter for Laravel that respects readability | | blade, laravel, php |formatter
| blue | The slightly less uncompromising Python code formatter | | python |formatter
| bpfmt | A formatter for Blueprint files | | blueprint |formatter
| brittany | Haskell source code formatter | | haskell |formatter
| brunette | A best practice Python code formatter | | python |formatter
| bsfmt | A code formatter for BrighterScript (and BrightScript) | | brighterscript, brightscript |linter
| bslint | A linter for BrightScript and BrighterScript | | brightscript, brightscripter |formatter
| buf | The best way of working with Protocol Buffers | | protobuf |formatter
| buildifier | A bazel BUILD file formatter and editor | | bazel |formatter
| cabal-fmt | An experiment of formatting .cabal files | | cabal |formatter
| cabal-gild | Format Haskell package descriptions | | cabal, haskell |formatter
| cabal-prettify | Prettify your Cabal package configuration files | | cabal |formatter
| cabal | Cabal is a system for building and packaging Haskell libraries and programs | | cabal |formatter
| caddy | Formats or prettifies a Caddyfile | | caddy |formatter
| caramel | Formatter for the Caramel programming language | | caramel |formatter
| cedar | Command Line Interface for Cedar | | cedar |linter
| cfn-lint | CloudFormation Linter | | cloudformation, json, yaml |linter
| checkmake | Linter/analyzer for Makefiles | | makefile |formatter
| clang-format | A tool to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code | | c#, c++, c, java, javascript, json, objective-c, protobuf |linter
| clang-tidy | clang-tidy is a clang-based C++ “linter” tool | | c++ |linter
| clj-kondo | Static analyzer and linter for Clojure code that sparks joy | | clojure, clojurescript |formatter
| cljfmt | A tool for formatting Clojure code | | clojure |formatter
| cljstyle | A tool for formatting Clojure code | | clojure |formatter
| cmake-format | cmake-format can format your listfiles nicely so that they don't look like crap | | cmake |linter
| cmake-lint | Lint CMake files | | cmake |formatter
| codeql | Format queries and libraries with CodeQL | | codeql |spell-check
| codespell | Check code for common misspellings | | |linter
| coffeelint | Lint your CoffeeScript | | coffeescript |linter
| cppcheck | Cppcheck is a static analysis tool for C/C++ code | | c++, c |linter
| cpplint | Static code checker for C++ | | c++ |formatter
| crlfmt | Formatter for CockroachDB's additions to the Go style guide | | go |formatter
| crystal | Tools for the Crystal programming language | | crystal |formatter
| csharpier | CSharpier is an opinionated code formatter for C# | | c# |formatter
| css-beautify | A CSS formatter | | css |formatter
| csscomb | CSS coding style formatter | | css |linter
| csslint | Automated linting of Cascading Stylesheets | | css |formatter
| cue | The home of the CUE language! Validate and define text-based and dynamic configuration | | cue |formatter
| cueimports | CUE tool that updates your import lines, adding missing ones and removing unused ones | | cue |linter
| curlylint | Experimental HTML templates linting for Jinja, Nunjucks, Django templates, Twig, Liquid | | django, html, jinja, liquid, nunjucks, twig |formatter
| d2 | A modern language that turns text to diagrams | | d2 |formatter
| dart | Formatter and linter for Dart | , linter | dart, flutter |formatter
| dcm | Code Quality Tool for Flutter Developers | , linter | dart, flutter |linter
| deadnix | Scan Nix files for dead code | | nix |formatter
| deno | Formatter and linter for JavaScript and TypeScript | , linter | javascript, json, typescript |formatter
| dfmt | Dfmt is a formatter for D source code | | d |formatter
| dhall | Format Dhall files | | dhall |formatter
| djade | A Django template formatter | | django, python |formatter
| djlint | Lint & Format HTML Templates | , linter | handlebars, html, jinja, mustache, nunjucks, twig |formatter
| docformatter | Formats docstrings to follow PEP 257 | | python |formatter
| dockerfmt | Dockerfile formatter. a modern dockfmt | | docker |gofmt
| dockfmt | Dockerfile format and parser. Like but for Dockerfiles | formatter | docker |formatter
| docstrfmt | A formatter for reStructuredText | | python, restructuredtext, sphinx |formatter
| doctoc | Generates table of contents for markdown files | | markdown |linter
| dotenv-linter | Lightning-fast linter for .env files | | env |formatter
| dprint | A pluggable and configurable code formatting platform written in Rust | | |linter
| dscanner | Swiss-army knife for D source code | | d |formatter
| dune | Build tool for OCaml projects | | dune, ocaml, reasonml |formatter
| duster | Automatic configuration for Laravel apps to apply Tighten's standard linting & code standards | , linter | php |formatter
| dx | Fullstack app framework for web, desktop, and mobile | | rsx, rust |formatter
| easy-coding-standard | The Easiest way to add coding standard to your PHP project | , linter | php |formatter
| efmt | Erlang code formatter | | erlang |formatter
| elm-format | elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide | | elm |linter
| eradicate | Removes commented-out code from Python files | | python |formatter
| erb-formatter | Format ERB files with speed and precision | | erb, ruby |linter
| erg | A statically typed language compatible with Python | | erg |formatter
| erlfmt | An automated code formatter for Erlang | | erlang |linter
| eslint | Find and fix problems in your JavaScript code | | javascript, typescript |formatter
| fantomas | FSharp source code formatter | | f# |formatter
| fish_indent | Fish indenter and prettifier | | fish |formatter
| fixjson | JSON Fixer for Humans using (relaxed) JSON5 | , linter | json5, json |formatter
| floskell | Floskell is a flexible Haskell source code pretty printer | | haskell |formatter
| flynt | A tool to automatically convert old string literal formatting to f-strings | | python |formatter
| fnlfmt | A formatter for Fennel code | | fennel |formatter
| forge | Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust | | solidity |linter
| fortitude | A Fortran linter | | |formatter
| fortran-linter | A simple fortran syntax checker, including automatic fixing of the code | , linter | fortran |formatter
| fourmolu | A fourk of ormolu that uses four space indentation and allows arbitrary configuration | | haskell |formatter
| fprettify | Auto-formatter for modern Fortran source code | | fortran |formatter
| futhark | Code formatter for the furhark programming language | | futhark |formatter
| fvm | Flutter Version Management: A simple CLI to manage Flutter SDK versions | , linter | dart, flutter |formatter
| gci | GCI, a tool that control golang package import order and make it always deterministic | | go |formatter
| gdformat | GDScript formatter | | gdscript |linter
| gdlint | GDScript linter | | gdscript |formatter
| gersemi | A formatter to make your CMake code the real treasure | | cmake |formatter
| ghokin | Parallelized formatter with no external dependencies for gherkin (cucumber, behat...) | | behat, cucumber, gherkin |formatter
| gleam | Format Gleam source code | | gleam |formatter
| gluon | A static, type inferred and embeddable language written in Rust | | gluon |formatter
| gofmt | Gofmt formats Go programs | | go |formatter
| gofumpt | A stricter gofmt | | go |formatter
| goimports-reviser | Right imports sorting & code formatting tool (goimports alternative) | | go |formatter
| goimports | goimports updates your Go import lines, adding missing ones and removing unreferenced ones | | go |formatter
| golangci-lint | Fast linters runner for Go | , linter | go |formatter
| golines | A golang formatter that fixes long lines | | go |formatter
| google-java-format | Reformats Java source code to comply with Google Java Style | | java |spell-check
| gospel | Misspelled word linter for Go comments, string literals and embedded files | | go |linter
| grafbase | The Grafbase command line interface | | graphql |formatter
| grain | Code formatter for the Grain programming language | | grain |linter
| hadolint | Dockerfile linter, validate inline bash, written in Haskell | | dockerfile |linter
| haml-lint | Tool for writing clean and consistent HAML | | haml |formatter
| hclfmt | Formatter for hcl files | | hcl |formatter
| hfmt | Format Haskell programs. Inspired by the gofmt utility | | haskell |formatter
| hindent | Haskell pretty printer | | haskell |linter
| hlint | Haskell source code suggestions | | haskell |formatter
| html-beautify | A html formatter | | html |formatter
| htmlbeautifier | A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates | | erb, html, ruby |linter
| htmlhint | The static code analysis tool you need for your HTML | | html |formatter
| hurlfmt | Formatter for hurl files | | hurl |formatter
| imba | A formatter for Imba | | imba |formatter
| inko | A language for building concurrent software with confidence | | inko |formatter
| isort | A Python utility to sort imports | | python |formatter
| janet-format | A formatter for Janet code. | | janet |formatter
| joker | Small Clojure interpreter, linter and formatter | , linter | clojure |formatter
| jq | Command-line JSON processor | | json |formatter
| jqfmt | like gofmt, but for jq | | jq` |
| js-beautify | Beautifi