Skip to main content

mdformat plugin that inserts Semantic Line Breaks (sembr.org) as CommonMark soft breaks

Project description

mdformat-sembr

Canonical home: codeberg.org/adel/mdformat-sembr — issues and contributions tracked there. The GitHub mirror exists solely to enable PyPI Trusted Publishing and provenance attestation.

⚠️ Disclaimer: This project was built using vibe-/agentic-coding

An mdformat parser-extension plugin that inserts Semantic Line Breaks (SemBr) as CommonMark soft breaks.

SemBr is a convention for adding line breaks in Markdown source at sentence and clause boundaries. Because the breaks are CommonMark soft breaks (a bare \n inside a paragraph), they render to a single space — the rendered HTML output is unchanged, only the source becomes more diff-friendly.

The plugin is fully deterministic: no ML, no network, no LLM calls. The same input always produces the same output.

Why

Moving SemBr logic out of an LLM/agent loop into a token-free, reproducible formatter pass makes authored Markdown consistent and cheap to maintain.

Install

# uv (recommended) — --with is repeatable (or comma-separate the plugins)
uv tool install mdformat --with mdformat-sembr --with mdformat-frontmatter

# pipx — install the app, then inject the plugins into its environment
pipx install mdformat
pipx inject mdformat mdformat-sembr mdformat-frontmatter

# local development
pip install -e .

mdformat-frontmatter is optional: install it only if your Markdown uses YAML/TOML frontmatter and you want mdformat to preserve/format it. It composes with mdformat-sembr (frontmatter is a separate node type and is never broken).

Usage

mdformat --version          # should list "mdformat_sembr"
echo "First sentence. Second sentence." | mdformat -

From Python:

import mdformat

mdformat.text("First sentence. Second sentence.\n", extensions={"sembr"})
# 'First sentence.\nSecond sentence.\n'

How it works

The plugin registers a postprocessor on the paragraph node type. At that point inline formatting (emphasis, links, inline code) is already resolved into the string, so it operates on the final rendered text and only protects a few inline constructs by regex. Block-level elements (headings, code blocks, tables, frontmatter, HTML blocks) are separate node types and are never touched.

CHANGES_AST = False: soft breaks are AST-safe by design, so mdformat's built-in is_md_equal validator gates correctness. If validation ever fails, the break logic is wrong — it is never worked around with --no-validate or hard breaks.

Configuration

Configure via [plugin.sembr] in .mdformat.toml, or via CLI flags. CLI values merge over TOML.

Option Type Default Meaning
min_chars int 15 Minimum length of the segment before a break is allowed.
abbreviations list[str] see below Tokens after which no sentence break is inserted.
break_clauses bool false Enable clause-level breaks (SemBr "SHOULD"). Off by default.
clause_chars str ",;:—" Clause punctuation set (only used when break_clauses true).

CLI flags: --sembr-min-chars, --sembr-abbreviations, --sembr-break-clauses, --sembr-clause-chars.

.mdformat.toml example:

[plugin.sembr]
min_chars = 20
break_clauses = true

License

MIT

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

mdformat_sembr-0.2.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

mdformat_sembr-0.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file mdformat_sembr-0.2.0.tar.gz.

File metadata

  • Download URL: mdformat_sembr-0.2.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mdformat_sembr-0.2.0.tar.gz
Algorithm Hash digest
SHA256 02d70fd35aecd3bf047771160553d000bda5a44fcda0080f2670d42abe3c2155
MD5 dbed09c21f50c16a1840bd21cae51136
BLAKE2b-256 efe63bb876a3d13166187d11974f30c09cd4902ff72ded713cf3f56c3a9a6c3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdformat_sembr-0.2.0.tar.gz:

Publisher: publish.yml on bugrasan/mdformat-sembr

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

File details

Details for the file mdformat_sembr-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mdformat_sembr-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mdformat_sembr-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f46887e2d6d2cfda5262592f447d978b1c5ac4512d51951e2b2195179e1315e8
MD5 37dfccc45ec666731a7b0731c7241ffc
BLAKE2b-256 7d3564e8694bce7500be8eb83cc24502a1924eb634a35b34ba05123851e01694

See more details on using hashes here.

Provenance

The following attestation bundles were made for mdformat_sembr-0.2.0-py3-none-any.whl:

Publisher: publish.yml on bugrasan/mdformat-sembr

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