Skip to main content

Better line wrapping and formatting for plaintext and Markdown

Project description

flowmark

Flowmark is a new Python implementation of text line wrapping and filling.

It simplifies and generalizes Python's textwrap with a few more capabilities:

  • Full customizability of initial and subsequent indentation strings

  • Control over when to split words, by default using a word splitter that won't break lines within HTML tags

In addition, it adds optional support for Markdown and offers Markdown auto-formatting, like markdownfmt, also with controllable line wrapping options.

One key use case is to normalize Markdown in a standard, readable way that makes diffs easy to read and use on GitHub. This can be useful for documentation workflows and also to compare LLM outputs that are Markdown.

Finally, it has options to use heuristics to split on sentences, which can make diffs much more readable. (For an example of this, look at the Markdown source of this readme file.)

It aims to be small and simple and have only a few dependencies, currently only marko and regex.

This is a new and simple package (previously I'd implemented something like this for Atom) but I plan to add more support for command line usage and VSCode/Cursor auto-formatting in the future.

Installation

The simplest way to use the tool is to use pipx:

pipx install flowmark

To use as a library, use pip or poetry to install flowmark.

Use in VSCode/Cursor

You can use Flowmark to auto-format Markdown on save in VSCode or Cursor. Install the "Run on Save" (emeraldwalk.runonsave) extension. Then add to your settings.json:

  "emeraldwalk.runonsave": {
    "commands": [
        {
            "match": "\\.md$",
            "cmd": "flowmark --auto ${file}"
        }
    ]
  }

The --auto option is just the same as --inplace --nobackup --sentences.

Usage

Flowmark can be used as a library or as a CLI.

$ flowmark --help
usage: flowmark [-h] [-o OUTPUT] [-w WIDTH] [-p] [-s] [-i] [--nobackup] [file]

Flowmark: Better line wrapping and formatting for plaintext and Markdown

positional arguments:
  file                 Input file (use '-' for stdin)

options:
  -h, --help           show this help message and exit
  -o, --output OUTPUT  Output file (use '-' for stdout)
  -w, --width WIDTH    Line width to wrap to
  -p, --plaintext      Process as plaintext (no Markdown parsing)
  -s, --sentences      Enable sentence-based line breaks (only applies to Markdown mode)
  -i, --inplace        Edit the file in place (ignores --output)
  --nobackup           Do not make a backup of the original file when using --inplace

Flowmark provides enhanced text wrapping capabilities with special handling for
Markdown content. It can:

- Format Markdown with proper line wrapping while preserving structure
  and normalizing Markdown formatting

- Optionally break lines at sentence boundaries for better diff readability

- Process plaintext with HTML-aware word splitting

It is both a library and a command-line tool.

Command-line usage examples:

  # Format a Markdown file to stdout
  flowmark README.md

  # Format a Markdown file and save to a new file
  flowmark README.md -o README_formatted.md

  # Edit a file in-place (with or without making a backup)
  flowmark --inplace README.md
  flowmark --inplace --nobackup README.md

  # Process plaintext instead of Markdown
  flowmark --plaintext text.txt

  # Use sentences to guide line breaks (good for many purposes git history and diffs)
  flowmark --sentences README.md

For more details, see: https://github.com/jlevy/flowmark

This project was built from simple-modern-poetry.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flowmark-0.2.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flowmark-0.2.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file flowmark-0.2.1.tar.gz.

File metadata

  • Download URL: flowmark-0.2.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flowmark-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d2ba0dcd24906fe11fa1cd134f068f7bc8959056cabc2e5b621e53c8c8b4fe71
MD5 18a0dbe41fffc09a37b525d5e112411f
BLAKE2b-256 b1705be9bb4e3e22d86e2cdcc911f14efdfa77bb26e9c402989501b5f15449df

See more details on using hashes here.

Provenance

The following attestation bundles were made for flowmark-0.2.1.tar.gz:

Publisher: publish.yml on jlevy/flowmark

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flowmark-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: flowmark-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flowmark-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f058fd32e22f3222442fff703181d206662a4e88bbf752195698adc761bcdc8a
MD5 b5358360b35d39a1a2bbc61b9c570b75
BLAKE2b-256 18ca0e0168c132b2c527f150a6b0654ec2b68e3e0e2627039a5fa27cb3c55786

See more details on using hashes here.

Provenance

The following attestation bundles were made for flowmark-0.2.1-py3-none-any.whl:

Publisher: publish.yml on jlevy/flowmark

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page