alto/commonmark-content-slicer

CommonMark extension that wraps heading-based sections in nested <section> elements for semantic document structure.

Maintainers

Package info

github.com/altophp/commonmark-content-slicer

Homepage

Issues

Documentation

pkg:composer/alto/commonmark-content-slicer

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-07-30 02:00 UTC

This package is auto-updated.

Last update: 2026-07-30 02:56:15 UTC


README

Summary

Genuinely rare in the CommonMark ecosystem. Most processors stop at rendering headings as <h1><h6> tags -- this one goes further and restructures the document into a properly nested <section> tree that mirrors the heading hierarchy. The result is semantic HTML you can actually target with CSS, query with JavaScript, and traverse with accessibility tooling. No custom syntax required.

Installation

composer require

composer require alto/commonmark

Registration

use Alto\CommonMark\Extension\ContentSlicer\ContentSlicerExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment();
$environment->addExtension(new ContentSlicerExtension());

Usage

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

Configuration

  • Constructor: new ContentSlicerExtension(int $minSectionLevel = 1).
  • 0 wraps from h1, 1 wraps from h2, 2 wraps from h3, etc.

Minimal Example

# Title
Intro

## Section

Body
### Subsection

Details

Development

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

License

MIT License -- Simon André & Alto