Add LimitHeadingsExtension to constrain heading levels#1113
Open
eyupcanakman wants to merge 1 commit intothephpleague:mainfrom
Open
Add LimitHeadingsExtension to constrain heading levels#1113eyupcanakman wants to merge 1 commit intothephpleague:mainfrom
eyupcanakman wants to merge 1 commit intothephpleague:mainfrom
Conversation
There was a problem hiding this comment.
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+LimitHeadingsProcessorwhich clampsHeadingnode levels onDocumentParsedEvent. - 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.
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new
LimitHeadingsExtensionto constrain heading levels to a configured min/max range.For example, with:
#headings are rendered as<h2>, and#####/######headings are rendered as<h4>.The extension observes
DocumentParsedEventand clamps heading nodes in the parsed AST. Configuration now validates both bounds (1..6) and themin_heading_level <= max_heading_levelinvariant.Also included:
Fixes #989