Skip to content

Formatting Issues with mdformat-mkdocs #45

@arv-anshul

Description

@arv-anshul

First of all, thank you for this amazing formatter. 🙏

I learned about mdformat-mkdocs from the @astral-sh/ruff repository.

When I tried using mdformat-mkdocs on my repository, I encountered some formatting issues that seem to stem from how the plugin handles specific mkdocs scenarios. I’m opening this issue to highlight these problems. If I’ve made any mistakes in my usage, please feel free to correct me.

⚙️ Configuration Used to Format My Repo

Initially, I used the formatter directly with pre-commit, as recommended. However, this formats all files in one go, making it difficult to identify specific issues.

To test individual files, I installed mdformat and mdformat-mkdocs using uvx:

uvx --from mdformat --with "mdformat-mkdocs[recommended]" mdformat docs/index.md

.mdformat.toml

wrap = 120
number = true
end_of_line = "lf"
validate = true

# The following doesn't work with the mdformat CLI.
# I have to explicitly specify the `--align-semantic-breaks-in-lists` flag.
[plugin.mkdocs]
align_semantic_breaks_in_lists = true
ignore_missing_references = false

As the [plugin.mkdocs] does work from .mdformat.toml so I have used this command to make it into effect.

uvx --from mdformat --with "mdformat-mkdocs[recommended]" mdformat --align-semantic-breaks-in-lists docs/index.md

Bug: Configuration Not Recognized

The configurations specified under the [plugin.mkdocs] section in .mdformat.toml are not recognized by the mdformat CLI. Other configurations work as expected. Please investigate and resolve this inconsistency.


Scenarios to Address

  • Attribute Lists: Using --wrap causes mdformat to split {:.class1 .class2} into a new line if it exceeds the wrapping limit. This breaks rendering since the attribute list is no longer correctly applied.
  • Jinja Templates: The same issue as above occurs with Jinja templates. While I’ve observed other formatting problems with Jinja, I will report them separately if they are within the scope of this plugin.
  •   Replacement: The formatter replaces   with a Unicode character. Is there a way to disable this behavior?
  • LaTeX Expressions: Pages containing LaTeX expressions often cause the formatter to throw the following error:
    Error: Could not format
    "path/to/page-containing-latex-expr.md".
    
    Formatted Markdown renders to different HTML than input Markdown. This is a bug
    in mdformat or one of its installed plugins. Please retry without any plugins
    installed. If this error persists, report an issue including the input Markdown
    on https://github.com/hukkin/mdformat/issues. If not, report an issue on the
    malfunctioning plugin's issue tracker.
    
    I understand that using --no-validate bypasses this issue, but a proper fix would be appreciated.

Sub-issues

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions