PHPackages                             czukowski/markdown-toc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. czukowski/markdown-toc

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

czukowski/markdown-toc
======================

Table of Contents generator for cebe/markdown

1.0.1(9y ago)75901MITPHPPHP &gt;=5.4.0

Since Sep 26Pushed 9y agoCompare

[ Source](https://github.com/czukowski/markdown-toc)[ Packagist](https://packagist.org/packages/czukowski/markdown-toc)[ Docs](https://github.com/czukowski/markdown-toc)[ RSS](/packages/czukowski-markdown-toc/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Table of Contents generator for cebe/markdown
=============================================

[](#table-of-contents-generator-for-cebemarkdown)

This package provides a PHP *trait* that to use with [cebe's Markdown implementation](https://github.com/cebe/markdown). It allows to generate ToC from headlines in Makrdown documents and render them as lists. Note: the output is a rendered HTML, not Markdown!

Installation
------------

[](#installation)

Recommended installation is via [composer](https://getcomposer.org/) by running:

```
composer require czukowski/markdown-toc "~1.0"

```

Alternatively you may add the following to the `require` section of your project's `composer.json`manually and then run `composer update` from the command line:

```
"czukowski/markdown-toc": "~1.0"
```

Usage
-----

[](#usage)

This package provides a `TOCTrait` that may be used in classes extending the cebe's original Markdown parsers.

For more information on how to extend the parser, refer to the [original Readme file](https://github.com/cebe/markdown#usage).

Generating Table of Contents can then be done by calling either of the two available public methods, depending on whether you are generating ToC from one or multiple files:

```
$markdown = new MyMarkdownWithTOC;

// Generate ToC from a single file:
$toc1 = $markdown->generateTableOfContents($source, 'index.md');

// Generate ToC from multiple files:
$toc2 = $markdown->generateTableOfContentsFromMultiple([
    [$intro, 'intro.md'],
    [$issues, 'issues.md'],
    [$reference, 'reference.md'],
]);
```

In the examples above, it's assumed that you've created a class named `MyMarkdownWithTOC` that uses `TOCTrait`.

Additional optional arguments are available that define the list type used and limit the headline levels that ToC is generated from.

Reference
---------

[](#reference)

- `generateTableOfContents($markdown, $url, $listType = 'ul', $fromLevel = 1, $toLevel = 6)`:

    - @param *string* `$markdown` markdown source.
    - @param *string* `$url` source URL.
    - @param *string* `$listType` supported values: `ul` and `ol`.
    - @param *integer* `$fromLevel` use headlines starting with this level
    - @param *integer* `$toLevel` use headlines up to this level
    - @return *string*
- `generateTableOfContentsFromMultiple($sources, $listType = 'ul', $fromLevel = 1, $toLevel = 6)`:

    - @param *array* `$sources` markdown sources and URLs.
    - @param *string* `$listType` supported values: `ul` and `ol`.
    - @param *integer* `$fromLevel` use headlines starting with this level
    - @param *integer* `$toLevel` use headlines up to this level
    - @return *string*

License
-------

[](#license)

The distribution is permitted under the MIT License. See LICENSE.md for details.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3563d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/186792?v=4)[Korney Czukowski](/maintainers/czukowski)[@czukowski](https://github.com/czukowski)

---

Top Contributors

[![czukowski](https://avatars.githubusercontent.com/u/186792?v=4)](https://github.com/czukowski "czukowski (5 commits)")

---

Tags

markdowntable-of-contentstocmarkdownindexTOCtable-of-contents

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/czukowski-markdown-toc/health.svg)

```
[![Health](https://phpackages.com/badges/czukowski-markdown-toc/health.svg)](https://phpackages.com/packages/czukowski-markdown-toc)
```

###  Alternatives

[erusev/parsedown

Parser for Markdown.

15.1k155.2M843](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

3.0k437.5M950](/packages/league-commonmark)[michelf/php-markdown

PHP Markdown

3.5k53.8M371](/packages/michelf-php-markdown)[league/html-to-markdown

An HTML-to-markdown conversion helper for PHP

1.9k31.0M276](/packages/league-html-to-markdown)[cebe/markdown

A super fast, highly extensible markdown parser for PHP

1.0k33.5M146](/packages/cebe-markdown)[cebe/markdown-latex

A super fast, highly extensible markdown parser for PHP, that converts markdown files into latex

50775.4k8](/packages/cebe-markdown-latex)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
