Skip to main content

An mdformat plugin for applying .editorconfig indentation settings.

Project description

mdformat-editorconfig

Build Status PyPI version

An mdformat plugin that applies EditorConfig indentation settings to Markdown formatting.

Motivation

mdformat uses opinionated defaults for indentation (2 spaces). This plugin allows you to configure indentation via .editorconfig files, making mdformat respect your project's or personal indentation preferences.

Installation

pip install mdformat-editorconfig

Or with pipx for command-line usage:

pipx install mdformat
pipx inject mdformat mdformat-editorconfig

Usage

Create an .editorconfig file in your project (or home directory):

# .editorconfig
root = true

[*.md]
indent_style = space
indent_size = 4

Then format your Markdown files as usual:

mdformat your-file.md

Example

With the above .editorconfig, nested lists will use 4-space indentation:

Before:

- Item 1
  - Nested item
- Item 2

After:

- Item 1
    - Nested item
- Item 2

Supported Properties

Property Values Description
indent_style space, tab Type of indentation
indent_size integer Number of columns per indentation level

How It Works

The plugin overrides mdformat's list renderers to apply indentation settings from .editorconfig files. It:

  1. Looks up .editorconfig settings based on the current working directory
  2. Reads indent_style and indent_size properties
  3. Applies the configured indentation to list continuation lines and nested content

CLI Usage

When using mdformat from the command line, the plugin looks up .editorconfig settings based on your current working directory. This means:

  • Run mdformat from your project root to pick up project-level .editorconfig
  • A global ~/.editorconfig (with root = true) will apply to all mdformat calls within your home directory
# Run from project root to use project's .editorconfig
cd /path/to/project
mdformat docs/*.md

Limitation

Due to mdformat's plugin architecture, the plugin cannot determine the actual file path being formatted. Instead, it uses the current working directory for .editorconfig lookup. This works well for the common case of running mdformat from a project root, but may not pick up the correct settings if you format files from a different directory.

Python API

When using the Python API directly, you can explicitly set the file context for more precise .editorconfig lookup:

import mdformat
from mdformat_editorconfig import set_current_file

# Set the file context for editorconfig lookup
set_current_file("/path/to/your/file.md")
try:
    result = mdformat.text(markdown_text, extensions={"editorconfig"})
finally:
    set_current_file(None)

Scope

This plugin currently handles indentation for:

  • Bullet lists (unordered lists)
  • Ordered lists

Code blocks and blockquotes follow CommonMark standard formatting (4-space indentation for indented code blocks).

Development

Setup

# Clone the repository
git clone https://github.com/jdmonaco/mdformat-editorconfig.git
cd mdformat-editorconfig

# Install development environment with uv
uv sync

Running Tests

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=mdformat_editorconfig

# Run tests verbosely
uv run pytest -v

License

MIT - see LICENSE file for details.

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_editorconfig-0.1.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

mdformat_editorconfig-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file mdformat_editorconfig-0.1.1.tar.gz.

File metadata

  • Download URL: mdformat_editorconfig-0.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for mdformat_editorconfig-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7eccb9035c0ec3eb248d77e9dbac2fdf23a7b86f4436a49f66c23a268dcd9961
MD5 ceb4a0c078467128fb7588f35c35aac0
BLAKE2b-256 159985867c1aeb927ab9cdf904b624eda3443b636c08633d930f18afe9ab57d5

See more details on using hashes here.

File details

Details for the file mdformat_editorconfig-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mdformat_editorconfig-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15055d2a6a30155ee3864a40961e1b7cf88ad00ef1df86b60ecb17bc932491f2
MD5 6a3db022d2d0806f45bdcab53eb455ff
BLAKE2b-256 1b32ce1fcb03e4e2abf190dfadc58a7aa06ab15b5fe525a931368405776ff623

See more details on using hashes here.

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