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 for the file being formatted
  2. Reads indent_style and indent_size properties
  3. Applies the configured indentation to list continuation lines and nested content

File Context

For the plugin to read .editorconfig settings, it needs to know the file path being formatted. When using the Python API directly with mdformat.text(), you can set the file context:

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)

When no file context is set, the plugin passes through to mdformat's default behavior (2-space indentation).

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.0.tar.gz (6.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_editorconfig-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mdformat_editorconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0bf08b48e5494d61425318a6343db4102585464ac3cbc2a74e9eee33e8b8e39c
MD5 f8c55751063547e29b2777fbd6def738
BLAKE2b-256 93e71cc47462548b2615da8d7233406fb4a16f266166c53aed60927f6b29db8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mdformat_editorconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3da56842babdf07fd605cc3dfa2b743c2425277edcf34233589db9176c3eabf
MD5 ded40e052e1a274ed3b549d3213acf6c
BLAKE2b-256 8f3db2058dcad619dee5793e1c777638d2664df73c8b917eae6aec8c01335733

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