An mdformat plugin for space control: EditorConfig indentation, tight lists, frontmatter spacing, and wikilinks.
Project description
mdformat-space-control
An mdformat plugin that provides unified control over Markdown spacing:
- EditorConfig support: Configure list indentation via
.editorconfigfiles - Tight list formatting: Automatically removes unnecessary blank lines between list items
- Frontmatter spacing: Normalizes spacing after YAML frontmatter (works with mdformat-frontmatter)
- Consecutive blank line normalization: Limits runs of 3+ empty lines to a maximum of 2
- Trailing whitespace removal: Strips trailing whitespace outside code blocks
- Escaped link repair: Fixes malformed multi-line links from web-clipped content
- Wikilink preservation: Handles Obsidian-style
[[links]],[[links|aliases]],[[page#heading]],[[page#^blockid]], and![[embeds]]
Installation
pip install mdformat-space-control
Or with pipx for command-line usage:
pipx install mdformat
pipx inject mdformat mdformat-space-control
Usage
After installation, mdformat will automatically use this plugin:
mdformat your-file.md
EditorConfig Support
Create an .editorconfig file in your project:
# .editorconfig
root = true
[*.md]
indent_style = space
indent_size = 4
Nested lists will use the configured indentation:
Before:
- Item 1
- Nested item
- Item 2
After (with 4-space indent):
- Item 1
- Nested item
- Item 2
Tight List Formatting
Lists with single-paragraph items are automatically formatted as tight lists:
Before:
- Item 1
- Item 2
- Item 3
After:
- Item 1
- Item 2
- Item 3
Multi-paragraph items preserve loose formatting:
- First item with multiple paragraphs
Second paragraph of first item
- Second item
Frontmatter Spacing
When used with mdformat-frontmatter, this plugin removes blank lines between the frontmatter closing delimiter and the first content block:
Before:
---
title: My Document
---
# Introduction
After:
---
title: My Document
---
# Introduction
Install both plugins for this feature:
pip install mdformat-space-control mdformat-frontmatter
EditorConfig Properties
| Property | Status | Notes |
|---|---|---|
indent_style |
Supported | space or tab for list indentation |
indent_size |
Supported | Number of spaces per indent level |
tab_width |
Supported | Used when indent_size = tab |
Python API
When using the Python API, you can set the file context for EditorConfig lookup:
import mdformat
from mdformat_space_control import set_current_file
set_current_file("/path/to/your/file.md")
try:
result = mdformat.text(markdown_text, extensions={"space_control"})
finally:
set_current_file(None)
Wikilink Preservation
Obsidian-style wikilinks are preserved during formatting:
Link to [[another note]] or [[note|with alias]].
Embed an image: ![[photo.jpg]]
Link to heading: [[note#section]]
Block reference: [[note#^blockid]]
Wikilinks inside markdown link text are correctly handled without duplication:
[![[image.jpg]]](http://example.com)
Compatible Plugins
This plugin is tested to work alongside:
- mdformat-frontmatter - YAML frontmatter parsing
- mdformat-simple-breaks - Normalizes thematic breaks to
---
For formatting files in an Obsidian vault, installing mdformat-frontmatter alongside this plugin is recommended:
pip install mdformat-space-control mdformat-frontmatter
Note: Wikilink support is built-in; mdformat-wikilink is not needed.
Development
# Install dependencies
uv sync
# Run tests
uv run python -m pytest
# Run with coverage
uv run python -m pytest --cov=mdformat_space_control
License
MIT - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdformat_space_control-0.3.0.tar.gz.
File metadata
- Download URL: mdformat_space_control-0.3.0.tar.gz
- Upload date:
- Size: 32.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20a44e912a5aa53963b4c52a2c9460a3310a7eb526d1b6a76d5803ffc3bb0a80
|
|
| MD5 |
8e719dacee00ed772060aa2e82c60080
|
|
| BLAKE2b-256 |
80a9eeb99e38b495325b8268c4dbd1233af27200a6525b2cc2573b823a0e5e06
|
File details
Details for the file mdformat_space_control-0.3.0-py3-none-any.whl.
File metadata
- Download URL: mdformat_space_control-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e8753fd7bd64416b687176990f456dcff91eedc1ebdc8ef8e32cc130a777bd9
|
|
| MD5 |
574c499ae4c03d1581ee422ec9b568f1
|
|
| BLAKE2b-256 |
2093cc5c8d3dc3be1de810e8e18cc539be6da6f1d10cfb37097460974b3d67b0
|