Wallogit.com
2017 © Pedro PelĂĄez
Markdown Table of Contents Generator
Generate a Table of Contents for your markdown files., (*1)
https://github.com/KeyboardCowboy/TopDown, (*2)
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., (*3)
Tell TopDown where the files live and the name of the TOC file to create., (*4)
$sidebar = new TopDown('/path/to/files');
$sidebar->create('TableOfContents.md');
This will create the file /path/to/files/TableOfContents.md, (*5)
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!, (*6)
There is a subclass to make generating GitHub Wiki sidebars super simple., (*7)
cd into it.composer require keyboardcowboy/topdown
Add a php file, for example buildSidebar.php to the repo then copy and paste this snippet:, (*8)
<?php require_once 'vendor/keyboardcowboy/topdown/TopDown.php'; $sidebar = new GitHubWikiSidebar(); $sidebar->create();
Now, simply run php buildSidebar.php! Thatâs it!, (*9)
TopDown relies on a simple naming convention to generate the hierarchy. By default a double-hyphen is used as the hierarchical separator, but you can tell TopDown to use any string as the separator. For example:, (*10)
contributing.md contributing--configuration.md contributing--configuration--advanced.md contributing--configuration--beginner.md contributing--getting-started.md contributing--giving-back.md more.md
Would generate a table of contents like this:, (*11)
TopDown reads the files out of the given directory top down, which is generally alphabetically, so to rearrange items simply prefix them with a number., (*12)
contributing.md contributing--1-getting-started.md contributing--2-configuration.md contributing--2-configuration--1-beginner.md contributing--2-configuration--2-advanced.md contributing--3-giving-back.md more.md
File names that begin with a number then a period or hyphen will have that part trimmed off to generate the link name., (*13)
TopDown::title string
TopDown::separator string
--.TopDown::format int
TopDown::UNORDERED.TopDown::fileExt bool
.md file extensions on its wiki page urls.TopDown::ignore array
TopDown::footer string
FALSE to disable the footer content.