What a Markdown formatter does
Markdown is forgiving. You can write a bullet with -, * or +, emphasis with * or _, and a heading with a row of equals signs or with #. That freedom is handy when you type, but a file edited by several people soon mixes every style. Tables drift out of line, blank lines go missing and diffs get noisy.
This formatter rewrites the source in one consistent style. It is built on Prettier, the formatter most JavaScript projects already use for their docs, so the output matches what Prettier gives in VS Code or on the command line.
How to use it
- Paste your Markdown into the left box, or press Open file to load a
.mdfile. Pasting formats it straight away. - Press Sample if you want to see an example first.
- Pick the Indent, the Line width and how to Wrap text: Keep as is, At line width or One line per paragraph.
- Press Format (or Ctrl and Enter) to run it again after you change something.
- Use Copy or Download to take the result. Clear empties the input.
Once you have formatted once, the output follows along as you type.
Before and after
Here is a short file written in a mixed style:
Project Notes
=============
* Install the tools
* Run the build
+ Deploy
|Name|Role|
|-|-|
|Ada|Admin|
|Linus|Editor|
Some *emphasis* and __bold__ text.
The formatter returns:
Project Notes
=============
- Install the tools
- Run the build
* Deploy
| Name | Role |
| ----- | ------ |
| Ada | Admin |
| Linus | Editor |
Some _emphasis_ and **bold** text.
A few things happened. A blank line now follows the heading. The first list uses -. Bold uses ** and italic uses _. The table columns are padded so they line up in plain text. Notice that “Deploy” stayed apart: it used a different bullet, so Markdown treats it as a second list, and the formatter keeps that meaning by giving it a different marker.
Wrapping long paragraphs
With Wrap text set to At line width and a line width of 60, this paragraph:
Markdown files are easier to review when each paragraph follows the same rule for line length, because a diff then shows only the sentence that changed.
becomes:
Markdown files are easier to review when each paragraph
follows the same rule for line length, because a diff then
shows only the sentence that changed.
One line per paragraph does the reverse and joins wrapped lines back together. Keep as is is the safe default when you do not know what your team expects.
What it leaves alone
The formatter changes layout, not meaning. Some things it deliberately does not touch:
- Code blocks. Code inside a fenced block stays exactly as written. A block marked
jsthat containsconst a={b:1}is not reformatted. Use the JavaScript formatter for that. - Numbered lists. If every item starts with
1., it keeps1.on every line. If you numbered them 1, 2, 3, it keeps that. - Text that is not valid syntax.
#Titlewithout a space is not a heading in CommonMark, so it stays a plain paragraph. Add the space and it becomes a heading. - Inline HTML. HTML tags inside your Markdown are kept as they are.
Tips
- Format before you commit. Consistent files mean the diff in a pull request only shows real edits.
- Pick one wrap rule for a whole repository. Mixing wrapped and unwrapped files causes large diffs the first time someone formats them.
- Building a table by hand is slow. The Markdown table generator gives you a grid to type in and pastes from spreadsheets.
- Need Markdown from a web page or a Word file? Use the HTML to Markdown converter or the Word to Markdown converter, then tidy the result here.
Other ways to format Markdown
- VS Code: install the Prettier extension, open a
.mdfile and run Format Document. The output matches this page. - Command line:
npx prettier --write README.mdformats a file in place. Add--prose-wrap alwaysto wrap paragraphs. - Linting: markdownlint checks style rules such as heading levels and line length. It reports problems, while a formatter fixes layout for you. Many projects use both.
Limits
The formatter follows CommonMark with GitHub extensions such as tables and task lists. Extensions from other tools, like custom containers or wiki links, are treated as plain text and may be spaced differently from what that tool expects. Front matter at the top of a file (the block between two --- lines) is kept. Very large files work, but formatting takes longer because it all happens on your device.