Skip to content

feat: add --normalize-front-matter#14

Open
KyleKing wants to merge 4 commits intomainfrom
feat-normalize
Open

feat: add --normalize-front-matter#14
KyleKing wants to merge 4 commits intomainfrom
feat-normalize

Conversation

@KyleKing
Copy link
Copy Markdown
Owner

No description provided.

@KyleKing KyleKing self-assigned this Mar 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

Walkthrough

This PR extends the front-matter plugin with configurable YAML normalization capabilities. It introduces a new --normalize-front-matter CLI option (with modes: none, minimal, 1.2) and updates the YAML handling implementation to use a RoundTripYAMLHandler that supports mode-specific transformations such as converting YAML 1.1 boolean words (yes/no/on/off) to YAML 1.2 equivalents and normalizing null representations. The public formatter APIs now accept a normalize_mode parameter, and documentation is updated with configuration examples and normalization behavior specifications. Two new test fixtures validate quote preservation and normalization across different modes.

Possibly related PRs


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@KyleKing KyleKing marked this pull request as ready for review March 24, 2026 20:18
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@mdformat_front_matters/_formatters.py`:
- Around line 58-83: The representer registrations for
_NullNormalizingRepresenter (the add_representer calls for type(None),
SingleQuotedScalarString, and DoubleQuotedScalarString which reference
_represent_as_plain_str) should be co-located with the class: move those
add_representer calls into the class body immediately after its docstring (or
implement __init_subclass__ on _NullNormalizingRepresenter to perform the
registrations at subclass creation), so the registration and the explanatory
docstring live together; ensure the lambda for null and the
_represent_as_plain_str reference remain unchanged and still target the same
tags/types.

In `@tests/format/fixtures/normalization.md`:
- Around line 39-52: The test title "YAML null unchanged under none" is
misleading because input `key: ~` is serialized as `key:` (representation
changed), so either rename the test to reflect that the representation is
normalized (e.g., "YAML null representation normalized (~ -> implicit) under
none") or update the code path that serializes YAML in "none" mode to preserve
`~` by adding a custom null representer in the ruamel.yaml serialization
routine; locate the test string "YAML null unchanged under none" in
normalization.md to change the title, or locate the YAML serializer/normalizer
function that handles "none" mode (the routine that invokes ruamel.yaml dumping)
and add/configure a null representer so `~` is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 87b5e923-ebf5-46b2-bff9-c5e094d9dc2f

📥 Commits

Reviewing files that changed from the base of the PR and between ee81761 and dd0c453.

📒 Files selected for processing (7)
  • AGENTS.md
  • README.md
  • mdformat_front_matters/_formatters.py
  • mdformat_front_matters/plugin.py
  • tests/format/fixtures/normalization.md
  • tests/format/fixtures/quote_preservation.md
  • tests/format/test_format.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant