PHPackages                             keyboardcowboy/topdown - 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. keyboardcowboy/topdown

ActiveLibrary

keyboardcowboy/topdown
======================

Markdown Table of Contents Generator

1.0.0(10y ago)023GPL-2.0+PHPPHP &gt;=5.5.0

Since Mar 2Pushed 10y agoCompare

[ Source](https://github.com/KeyboardCowboy/TopDown)[ Packagist](https://packagist.org/packages/keyboardcowboy/topdown)[ RSS](/packages/keyboardcowboy-topdown/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

TopDown
=======

[](#topdown)

**Generate a Table of Contents for your markdown files.**

This was inspired by the GitHub wiki. Its usefulness is trumped by the the fact that the sidebar is in no way connected to the wiki pages. You can break a link by changing a page name. With TopDown you can generate a simple Table of Contents, for example the `_Sidebar.md` file in GitHub, just by using a simple naming convention.

How it Works
------------

[](#how-it-works)

1. Install this library.
2. Create a PHP file and include TopDown.php.
3. Tell TopDown where the files live and the name of the TOC file to create.

    ```
     $sidebar = new TopDown('/path/to/files');
     $sidebar->create('TableOfContents.md');

    ```

This will create the file `/path/to/files/TableOfContents.md`

With GitHub
-----------

[](#with-github)

GitHub wikis are their own repos. Check yours out to your local machine instead of editing the files in the UI. When you are done creating or editing your files, run TopDown and your sidebar is ready to go!

There is a subclass to make generating GitHub Wiki sidebars super simple.

1. Check out your wiki repo and `cd` into it.
2. Run `composer require keyboardcowboy/topdown`
3. Add a php file, for example `buildSidebar.php` to the repo then copy and paste this snippet:

    ```
