Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HeadingLevel Extension

Summary

The one you don't need until you really do -- then it's irreplaceable. Transforms heading levels after parsing so that content written for one heading context can be safely embedded in another without hierarchy collisions. Supports fixed shifting, explicit level remapping, and a callback option that gives you complete control over every heading in the document.

Installation

composer require

composer require alto/commonmark

Registration

use Alto\CommonMark\Extension\HeadingLevel\HeadingLevelExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment();
$environment->addExtension(new HeadingLevelExtension(['down' => 1]));

Usage

No custom markdown directive is required; the extension processes standard headings after parse.

Configuration

  • ['down' => 1]: shifts heading level up numerically (h1 -> h2, etc.).
  • ['map' => [1 => 2, 2 => 3]]: explicit per-level mapping.
  • ['callback' => fn(int $level): int => ...]: custom transformation logic.

Minimal Example

# Original H1

## Original H2

Development

This extension is actively developed in the alto/commonmark monorepo.

License

MIT License -- Simon André & Alto

About

CommonMark extension that shifts, maps, or transforms heading levels via a config array or callback.

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

Contributors

Languages