A small Rust program that wraps markdown files. Uses the comrak AST library so that rendering remains accurate.
Write wrapped input.md to output.md.
mdwrap -f input.md -o output.md
Write wrapped markdown from stdin to stdout
mdwrap
As a vim command
%!mdwrap
With formatter.nvim and lazy.nvim (plugin manager).
local function wrapper()
return {
exe = "mdwrap",
args = { "-l", "70" }, -- or whatever line width you want
stdin = true,
}
end
return {
"mhartington/formatter.nvim",
config = function(plugin)
local formatter_setup = {
logging = false,
filetype = {
markdown = { wrapper },
},
}
require("formatter").setup(formatter_setup)
end,
cmd = "FormatWrite",
}