flowmark
What Is Flowmark?
Flowmark is a Markdown auto-formatter, written
in Python with an auto-synced
Rust port, designed for better LLM
workflows, clean git diffs, and flexible use from CLI, from IDEs, or as a
library.
With AI tools increasingly producing Markdown, consistent and diff-friendly formatting
has become essential.
It improves collaborative editing and LLM workflows, especially when committing
documents to git repositories.
For CLI auto-formatting, the Python and Rust builds produce identical output: the Rust
port is a fast single native binary, while the Python version is the reference and is
sometimes ahead on the newest features.
Pick whichever fits your environment; for heavy or latency-sensitive formatting, choose
the Rust binary.
Quick Start
Both Python and Rust versions are best installed with
uv.
Run With uvx
No install needed for one-off usage:
uvx --from flowmark-rs==0.4.0 flowmark --help
uvx --from flowmark-rs==0.4.0 flowmark --auto somefile.md
uvx --from flowmark==0.8.0 flowmark --help # Python reference
Install as a Global CLI
uv tool install flowmark-rs==0.4.0 # Native Rust CLI
flowmark --auto somefile.md # One file
flowmark --auto . # Whole tree
Run flowmark --help, flowmark --docs, or flowmark --skill for more.
Set Up with Any Coding Agent
Hand your agent this one instruction:
Set up Flowmark to keep this project’s Markdown auto-formatted.
Install the Flowmark skill with npx skills add jlevy/flowmark@flowmark and follow
it.
Or install the skill into .agents/, .claude/, and AGENTS.md directly:
uvx --from flowmark-rs==0.4.0 flowmark --install-skill
See How to Install the Skill for the available surfaces.
For consistency across users and supply chain security, it’s recommended to pin the
version when installing within a skill or project build.
Why Another Markdown Auto-Formatter?
Flowmark supports both CommonMark and
GitHub-Flavored Markdown (GFM) via
Marko.
The key differences from
other Markdown formatters:
Carefully chosen default formatting rules that are effective for use in editors/IDEs,
in agent pipelines, and also when paging through docs in a terminal.
Extensive Markdown feature support.
“Just works” support including GFM-style tables, footnotes, YAML
frontmatter, template tags (Markdoc, Jinja, Nunjucks), and inline HTML and
HTML comments.
Source-exact preservation of syntax that is not safe
to re-render, including LaTeX math, Pandoc, Obsidian, MyST, and
GitLab syntax. These come back byte for byte, while the prose around them is
wrapped and cleaned up normally.
There are no dialect flags to set.
All line wrapping is Markdown-aware.
Flowmark offers advanced and customizable line-wrapping capabilities, including
semantic line breaks, a feature that is especially helpful in
managing diffs and allowing collaborative edits on a Markdown document while avoiding
git conflicts.
Optional typographic fixes such as automatic smart quotes for
professional-looking typography.
Full-featured globbing, including git-ignore support.
A fast, exact Rust port of the Python reference implementation, compiled to a
single native binary.
With the Rust port’s caching feature, it can auto-format thousands of documents in
milliseconds.
Some general philosophy:
Be conservative about changes so that it is safe to run automatically on save or after
any stage of a document pipeline.
Be opinionated about sensible defaults but not dogmatic by preventing customization.
You can adjust or disable most settings.
And if you are using it as a library, you can fully control anything you want
(including more complex things like custom line wrapping for HTML).
Be as small and simple as possible, with few dependencies.
Use Cases
The main ways to use Flowmark are:
To autoformat Markdown on save in VSCode/Cursor or any other editor that supports
running a command on save.
See below for recommended VSCode/Cursor setup.
As a command line formatter to format text or Markdown files using the flowmark
command.
As a library to autoformat Markdown from document pipelines.
For example, it is great to normalize the outputs from LLMs to be consistent, or to
run on the inputs and outputs of LLM transformations that edit text, so that the
resulting diffs are clean.
As a more powerful drop-in replacement library for Python’s default
textwrap but with more options.
It simplifies and generalizes that library, offering better control over initial and
subsequent indentation and when to split words and lines, e.g. using a word
splitter that won’t break lines within HTML tags, template tags ({% %}, {# #},
{{ }}), Markdown links (including links with multi-word text), inline code spans
(`code with spaces`), or HTML comments.
See
wrap_paragraph_lines.
Semantic Line Breaks
[!TIP]
For an example of what an auto-formatted Markdown doc looks with semantic line breaks
looks like, see
the Markdown source
of this readme file.
Some Markdown auto-formatters never wrap lines, while others wrap at a fixed width.
Flowmark supports both, via the --width option.
Default line wrapping behavior is 88 columns. The
“90-ish columns” compromise
was popularized by Black and also works well for Markdown.
However, in addition, unlike traditional formatters, Flowmark also offers the option to
use a heuristic that prefers line breaks at sentence boundaries.
This is a small change that can dramatically improve diff readability when collaborating
or working with AI tools.
This idea of semantic line breaks, which is breaking lines in ways that make sense
logically when possible (much like with code) is an old one.
But it usually requires people to agree on how to break lines, which is both difficult
and sometimes controversial.
However, now we are using versioned Markdown more than ever, it’s a good time to revisit
this idea, as it can make diffs in git much more readable. The change may seem
subtle but avoids having paragraphs reflow for very small edits, which does a lot to
minimize merge conflicts.
This is my own refinement of
traditional semantic line breaks.
Instead of just allowing you to break lines as you wish, it auto-applies fixed
conventions about likely sentence boundaries in a conservative and reasonable way.
It uses simple and fast regex-based sentence splitting. While not perfect, this
works well for these purposes (and is much faster and simpler than a proper sentence
parser like SpaCy). It should work fine for English and many other Latin/Cyrillic
languages, but hasn’t been tested on CJK. You can see some
old discussion of this idea with
the markdownfmt author.
While this approach to line wrapping may not be familiar, I suggest you just try
flowmark --auto on a document and you will begin to see the benefits as you
edit/commit documents.
This feature is enabled with the --semantic flag or the --auto convenience flag.
Typographic Cleanups
Smart Quote Support
Flowmark offers optional automatic smart quotes to convert "non-oriented quotes"
to “oriented quotes” and apostrophes intelligently.
This is a robust way to ensure Markdown text can be converted directly to HTML with
professional-looking typography.
Smart quotes are applied conservatively and won’t affect code blocks, so they don’t
break code snippets.
It only applies them within single paragraphs of text, and only applies to ' and "
quote marks around regular text.
This feature is enabled with the --smartquotes flag or the --auto convenience flag.
Ellipsis Support
There is a similar feature for converting ... to an ellipsis character … when it
appears to be appropriate (i.e., not in code blocks and when adjacent to words or
punctuation).
This feature is enabled with the --ellipses flag or the --auto convenience flag.
Frontmatter Support
Because YAML frontmatter is common on Markdown files, any YAML frontmatter (content
between --- delimiters at the front of a file) is always preserved exactly.
YAML is not normalized.
[!TIP]
See the frontmatter format repo for
more discussion of YAML frontmatter and its benefits.
Source-Exact Preservation
Some Markdown syntax is not safe to re-render.
A formatter that “normalizes” a LaTeX equation or rewrites the delimiters of a code span
has corrupted the document, even if the result still parses.
Flowmark recognizes these constructs before parsing, formats everything around them
normally, and restores the authored bytes exactly.
Nothing needs to be enabled and there are no dialect flags.
Given notes.md:
Prose "here" gets smart quotes... and this sentence is long enough that Flowmark rewraps it.
Let $x_i = "a"...$ stay exactly as written.
flowmark --auto notes.md rewraps the prose and applies smart quotes and an ellipsis,
while the math keeps its straight quotes, literal dots, and spacing:
Prose “here” gets smart quotes … and this sentence is long enough that Flowmark rewraps
it.
Let $x_i = "a"...$ stay exactly as written.
What is preserved:
Math: Inline $...$, display $$...$$, bracket forms \(...\) and \[...\],
and LaTeX environments such as \begin{align}.
Inline code: The authored backtick run and body, including awkward cases like
``a `b` "c"...``.
Pandoc: Grid tables, multiline tables, definition lists, and line blocks.
Obsidian and MyST: Callouts (> [!NOTE]), roles ({ref}`target`), and
wikilinks ([[Page]]).
GitLab: Multiline blockquotes (>>>) and references such as [issue:_123_].
Other syntax: Fenced divs and colon containers (:::), TOML frontmatter (+++),
attribute groups ({#id .class}), and raw HTML blocks.
Usage
Flowmark can be used as a library or as a CLI.
Quick Start
# Format all Markdown files in current directory recursively
flowmark --auto .
# Format a single file in-place with all auto-formatting options
flowmark --auto README.md
# List files that would be formatted (without formatting)
flowmark --list-files .
# Format to stdout
flowmark README.md
# Format from stdin (use '-' explicitly)
echo "Some text" | flowmark -
Batch Formatting
The simplest way to format all Markdown in a project:
flowmark --auto .
This recursively discovers all .md files, skips common non-content directories
(node_modules, .venv, build, etc.), respects .gitignore, and formats everything
in-place with semantic line breaks, smart quotes, ellipses, and cleanups.
For a legacy alternative (pre-v1.0 behavior):
find . -name "*.md" -exec flowmark --auto {} \;
CLI Reference
The main flags:
| Flag |
Description |
-o, --output FILE |
Output file (use - for stdout) |
-w, --width WIDTH |
Line width (default: 88, 0 = disable wrapping) |
-p, --plaintext |
Process as plaintext (no Markdown parsing) |
-s, --semantic |
Semantic (sentence-based) line breaks |
-c, --cleanups |
Safe cleanups (unbold headings, etc.) |
--smartquotes |
Convert straight quotes to typographic quotes |
--ellipses |
Convert ... to … |
--list-spacing |
Control list spacing: preserve, loose, tight |
-i, --inplace |
Edit in place |
--nobackup |
Skip .orig backup with --inplace |
--check |
Don’t write; exit non-zero if any file would be reformatted (for CI / pre-commit) |
--auto |
All auto-formatting: --inplace --nobackup --semantic --cleanups --smartquotes --ellipses. Requires file/directory args (use . for current directory) |
File discovery flags: