A Go-based markdown formatter that reformats markdown files with one sentence per line.
- Uses goldmark, a well-maintained CommonMark-compliant markdown parser
- Formats paragraphs with one sentence per line
- Preserves markdown structure:
- Headers
- Lists (both ordered and unordered)
- Code blocks (fenced and indented)
- Blockquotes
- Inline formatting (bold, italic, links, images, inline code)
- Horizontal rules
- Preserves original formatting choices:
- List markers (-, *, +)
- Ordered list delimiters (., ))
- Link and image titles
- Code fence languages
Formatting markdown with one sentence per line makes it easier to:
- Track changes in version control (git diffs are clearer)
- Review and edit individual sentences
- Collaborate on documents
go buildInstall using mise with the Go backend:
mise use -g go:github.com/neongreen/mono/markdown-format@mainOr add to your .mise.toml:
[tools]
"go:github.com/neongreen/mono/markdown-format" = "main"Format files in place (default behavior):
./markdown-format file1.md file2.md file3.mdCheck if files are formatted without modifying them:
./markdown-format --check file1.md file2.mdFormat from stdin to stdout:
cat input.md | ./markdown-formatOr:
./markdown-format < input.md > output.mdInput:
# Hello
This is a paragraph. It has multiple sentences. Let's format it!Output:
# Hello
This is a paragraph.
It has multiple sentences.
Let's format it!markdown-format preserves most of your original markdown formatting:
- ✅ List markers (-, *, +) - each marker type is preserved
- ✅ Ordered list delimiters (., )) - both
1.and1)styles are preserved - ✅ Link and image titles
- ✅ Code fence languages
- ✅ Inline formatting styles (bold, italic, code, links)
- ✅ All markdown structure (headings, lists, blockquotes, code blocks, etc.)
Some formatting details are normalized to canonical forms:
⚠️ Thematic breaks (horizontal rules) are normalized to---⚠️ Setext-style headings are converted to ATX-style (#prefixes)⚠️ Emphasis markers may be normalized (both*and_work, but output may vary)
This is due to the limitations of AST-based markdown parsers. No standard CommonMark parser provides truly lossless roundtrip because the CommonMark specification allows multiple valid syntaxes for the same output, and parsers normalize to canonical forms.
The primary goal of this tool is to format with one sentence per line while preserving the most important formatting choices. The normalized items above are edge cases that don't affect the readability or structure of your documents.
See the examples/ directory for complete configuration files and sample markdown files demonstrating the integrations.
treefmt is a universal code formatter that runs multiple formatters with one command.
Add to your treefmt.toml:
[formatter.markdown-format]
command = "markdown-format"
includes = ["*.md"]Then run:
treefmtdprint is a pluggable and configurable code formatter.
To integrate markdown-format with dprint, use the exec plugin. First, install the exec plugin if you haven't already:
dprint config add execThen add to your dprint.json:
{
"exec": {
"commands": [{
"command": "markdown-format",
"exts": ["md"]
}]
},
"plugins": [
"https://plugins.dprint.dev/exec-0.5.0.json@<hash>"
]
}The exec plugin will handle passing files to markdown-format for in-place formatting.
Run dprint:
dprint fmtMIT License - See LICENSE file in the repository root.