Context
Context
Provide background to help others understand this issue.
The current configuration loading logic relies on recursive file tree traversal to find a file named .mdformat.toml or loading from Path.cwd() for stdin. This auto-discovery model is simple but inflexible for complex projects.
Describe the problem or need you'd like to address.
The reliance on a fixed filename and recursive search creates friction for users who manage configuration:
- Pre-commit Integration: When using
mdformat in a .pre-commit-config.yaml hook alongside other tools (like markdownlint or hadolint), it is standard practice to store all configuration files in a shared directory (e.g., .config/). Most tools support explicitly loading a config via a --config flag, but mdformat does not, forcing an exception to the directory structure.
- Centralized Configuration: Users cannot explicitly point
mdformat to a configuration file located outside the file's directory path (e.g., at the root level in a path like .config/mdformat.toml), complicating centralized maintenance.
The core problem is the lack of a mechanism to override the default config discovery path.
Proposal
Proposal
A simple and clear description of what you're proposing.
Introduce a new optional command-line flag, --config <path>, that allows a user to specify the absolute or relative path to a single configuration file.
This explicit path must override the default auto-discovery mechanism. If a path is provided via --config, mdformat should only attempt to load settings from that single file and ignore any .mdformat.toml files in the directory tree.
Ideas or constraints for how to implement this proposal
- The flag should be defined with
type=Path in argparse.
- The implementation should include a new internal function to load configuration directly from the provided path, separate from the cached recursive lookup function.
- If the file specified by
--config does not exist, mdformat must print an error and exit with a non-zero code (e.g., 1), similar to how it handles formatting errors.
Important considerations to think about or discuss
- Precedence: The
--config argument must take the highest precedence, overriding both recursive file discovery and any other implicit config loading (like pyproject.toml if extensions are used).
- Compatibility: Since the config file format remains TOML (
.mdformat.toml syntax), compatibility with all existing options (wrap, number, plugin.*, etc.) is maintained.
Context
Context
Provide background to help others understand this issue.
The current configuration loading logic relies on recursive file tree traversal to find a file named
.mdformat.tomlor loading fromPath.cwd()for stdin. This auto-discovery model is simple but inflexible for complex projects.Describe the problem or need you'd like to address.
The reliance on a fixed filename and recursive search creates friction for users who manage configuration:
mdformatin a.pre-commit-config.yamlhook alongside other tools (likemarkdownlintorhadolint), it is standard practice to store all configuration files in a shared directory (e.g.,.config/). Most tools support explicitly loading a config via a--configflag, butmdformatdoes not, forcing an exception to the directory structure.mdformatto a configuration file located outside the file's directory path (e.g., at the root level in a path like.config/mdformat.toml), complicating centralized maintenance.The core problem is the lack of a mechanism to override the default config discovery path.
Proposal
Proposal
A simple and clear description of what you're proposing.
Introduce a new optional command-line flag,
--config <path>, that allows a user to specify the absolute or relative path to a single configuration file.This explicit path must override the default auto-discovery mechanism. If a path is provided via
--config,mdformatshould only attempt to load settings from that single file and ignore any.mdformat.tomlfiles in the directory tree.Ideas or constraints for how to implement this proposal
type=Pathinargparse.--configdoes not exist,mdformatmust print an error and exit with a non-zero code (e.g., 1), similar to how it handles formatting errors.Important considerations to think about or discuss
--configargument must take the highest precedence, overriding both recursive file discovery and any other implicit config loading (likepyproject.tomlif extensions are used)..mdformat.tomlsyntax), compatibility with all existing options (wrap,number,plugin.*, etc.) is maintained.