A flexible command-line tool for normalizing and customizing Markdown styles.
- Unify bold, italic, horizontal rules (hr), and list markers with your preferred symbols
- Preserve code blocks completely
- Remove unnecessary escape characters (
\*,\\[etc.) — optional - Clean up extra blank lines in lists (especially those generated by Notepad) — optional
-
Clone the repository
git clone https://github.com/shachi-lab/md-formatter.git cd markdown-formatter -
Grant execution permission (Linux/macOS)
chmod +x md_formatter.py
-
(Optional) Create a symbolic link
ln -s $(pwd)/md_formatter.py /usr/local/bin/mdfmt
Linux / macOS
- You can make it executable and link it as shown above.
Windows
- No need for
chmodor symbolic links.
Run directly from Python:python md_formatter.py input.md > output.md - Optionally, create a
.batfile to use it as a shortcut command.
# Format input.md and output to output.md
./md_formatter.py input.md > output.md# Set bold to '_', italic to '-', horizontal rule to '*', and list marker to '+'
./md_formatter.py \
--bold _ \
--italic - \
--hr * \
--list + \
input.md > output.md# Keep escape characters and disable list formatting
./md_formatter.py --no-del-escape --no-fix-list input.md > output.md#### Format Markdown file and output to stdout
./md_formatter.py input.md > output.md## Change italic to underscore, bold to *, and hr to *
./md_formatter.py --italic _ --bold * --hr * input.md| Option | Description | Default |
|---|---|---|
--bold {*, -, _} |
Select bold marker | * |
--italic {*, -, _} |
Select italic marker | * |
--hr {*, -, _} |
Select horizontal rule marker | - |
--list {*, -, +} |
Select list marker | - |
--no-del-escape |
Keep backslash-escaped characters | false |
--no-fix-list |
Disable list cleanup | false |
-
Code blocks
- Sections wrapped by triple backticks ``` are preserved as-is.
-
Escape character removal (
--no-del-escapenot specified)- Removes unnecessary
\before Markdown syntax (e.g.\*,\[, etc.)
- Removes unnecessary
-
List formatting (
--no-fix-listnot specified)- Removes extra blank lines between list items inserted by Notepad.
-
Horizontal rule conversion
- Normalizes various hr markers like
---,***,___to the selected symbol repeated three times.
- Normalizes various hr markers like
Bug reports and pull requests are welcome!
- Open an issue
- Fork and create a new branch
- Make changes and submit a pull request
MIT License © [Shachi-lab]