Skip to main content

Linebreaker

I created this tool because I couldn't find a reliable line breaking utility that works with Quarto markdown without altering headers, lists, or other formatting. This tool is conservative - it preserves your document structure and only adds line breaks when both the preceding and following text segments are sufficiently long.

Features

Intelligent line breaking for Markdown and text files, with support for:

  • Citations in format [@...]
  • Decimal numbers
  • Common abbreviations (Dr., Prof., vs., et al., etc.)
  • YAML headers
  • Code blocks
  • Soft breaks on conjunctions, commas, and/or

Installation

Install from PyPI using pixi:

pip install linebreaker
pixi add --pypi linebreaker

Or install from source:

git clone https://github.com/silas/linebreaker.git
cd linebreaker
pixi install

Usage

As a command-line tool:

# Process a single file
linebreaker your_file.md

# Process a directory
linebreaker writing/

# For compatibility, you can still use the old script
python -m linebreaker.cli your_file.md

⚠️ Important: Only use this tool on files that are tracked by a version control system like Git. Line breaking modifies your files, and having version control ensures you can review and revert changes if needed.

As a module:

from linebreaker import format_line, break_text

# Format a single line
result = format_line("Your text here...")

# Process entire text with YAML/code blocks
result = break_text(full_text)

Running Tests

# Run all tests
pytest linebreaker/tests/

Detailed Features

Hard Breaks (Sentence Boundaries)

  • Splits on ., ?, ! when both before and after have 20+ characters
  • Avoids common abbreviations: vs., Dr., Prof., Mr., Mrs., Ms., Ph.D., M.D., Jr., Sr., etc., e.g., i.e., et al., vol., no., pp., fig.

Medium Breaks (Colons/Semicolons)

  • Splits sentences longer than 80 characters at : or ;
  • Only if both parts have 20+ characters

Soft Breaks (Conjunctions)

  • Applied when there are 3+ sentences or sentence is >60 characters
  • Breaks on: but, such as, for example, e.g., i.e. (after 20 chars)
  • Breaks on commas (after 40 chars)
  • Breaks on and, or (after 40 chars)

Smart Masking

  • Citations [@...] are masked to prevent dots inside from triggering breaks
  • Decimal numbers like 0.85 are masked similarly

Development

To add new abbreviations, edit the abbreviations pattern in core.py:

abbreviations = r'(?!vs\.|dr\.|prof\.|...|your_abbrev\.)'

Metadata

Release files for linebreaker 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linebreaker 0.0.0
File Size Uploaded Provenance
linebreaker-0.0.0.tar.gz 16.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for linebreaker 0.0.0
File Interpreter ABI Platform
linebreaker-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.1 kB

Release files / linebreaker-0.0.0.tar.gz

Download URL linebreaker-0.0.0.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fdee2bb84ac2e492f2e15853758a5f9f89d9a044e48d2526531c695cb679c650
BLAKE2b-256 checksum
How to use checksums
f556d41aaac60c3cbbe911779a67c2af0db17f5685184c6ccbcfc3be03ce4e45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / linebreaker-0.0.0-py3-none-any.whl

Download URL linebreaker-0.0.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a764522a012a778a1f22c105ed41ce8a29221d38140dd8189cfa2c623106bd4
BLAKE2b-256 checksum
How to use checksums
d3276c3fc3eb0d0ebdb0b7ed69b49440e88ea2a092a9274439270d66e4ef997e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for linebreaker 0.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page