Skip to content

Add LimitHeadingsExtension to constrain heading levels#1113

Open
eyupcanakman wants to merge 1 commit intothephpleague:mainfrom
eyupcanakman:feat/limit-headings-extension-989
Open

Add LimitHeadingsExtension to constrain heading levels#1113
eyupcanakman wants to merge 1 commit intothephpleague:mainfrom
eyupcanakman:feat/limit-headings-extension-989

Conversation

@eyupcanakman
Copy link

This adds a new LimitHeadingsExtension to constrain heading levels to a configured min/max range.

For example, with:

'limit_headings' => [
    'min_heading_level' => 2,
    'max_heading_level' => 4,
],

# headings are rendered as <h2>, and ##### / ###### headings are rendered as <h4>.

The extension observes DocumentParsedEvent and clamps heading nodes in the parsed AST. Configuration now validates both bounds (1..6) and the min_heading_level <= max_heading_level invariant.

Also included:

  • unit and functional tests (including HeadingPermalink + TableOfContents interoperability)
  • extension docs page + overview/menu updates
  • changelog entry

Fixes #989

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new LimitHeadingsExtension to clamp parsed heading levels into a configurable min/max range, enabling “allowed heading levels” behavior similar to other editors.

Changes:

  • Introduces LimitHeadingsExtension + LimitHeadingsProcessor which clamps Heading node levels on DocumentParsedEvent.
  • Adds unit + functional coverage (including interoperability with Heading Permalinks and Table of Contents).
  • Updates documentation navigation/overview, adds a new docs page, and records the change in the changelog.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Extension/LimitHeadings/LimitHeadingsExtension.php Defines config schema (bounds + invariant) and registers the event listener with appropriate priority.
src/Extension/LimitHeadings/LimitHeadingsProcessor.php Implements the AST traversal and heading level clamping behavior.
tests/unit/Extension/LimitHeadings/LimitHeadingsProcessorTest.php Unit-level verification of clamping/default behavior and invalid config handling.
tests/functional/Extension/LimitHeadings/LimitHeadingsExtensionTest.php Functional tests for fixture-based conversions and ordering vs. TOC/permalinks.
tests/functional/Extension/LimitHeadings/md/clamps-levels.md Functional input fixture for ATX heading clamping behavior.
tests/functional/Extension/LimitHeadings/md/clamps-levels.html Expected HTML output for ATX clamping fixture.
tests/functional/Extension/LimitHeadings/md/clamps-setext-and-atx.md Functional input fixture ensuring both Setext + ATX headings are clamped.
tests/functional/Extension/LimitHeadings/md/clamps-setext-and-atx.html Expected HTML output for Setext + ATX clamping fixture.
docs/_data/menu.yml Adds “Limit Headings” to the extensions menu.
docs/2.x/extensions/overview.md Adds the extension to the extensions overview list and reference link set.
docs/2.x/extensions/limit-headings.md New documentation page describing installation, usage, and configuration.
CHANGELOG.md Adds an Unreleased changelog entry for the new extension.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@phpfui phpfui mentioned this pull request Mar 20, 2026
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.

2 participants