Skip to content

C. Editing this Wiki

Brian Clapper edited this page Oct 28, 2019 · 1 revision

When editing (or adding pages to) this wiki, please add a table of contents for each page, if the page has any headings. GitHub Wiki doesn't support doing that automatically within a page.

In the main repo, in the top-most directory, you'll find an mdtoc.py program. That program:

  • reads a Markdown document, looking for all headings,
  • ignores any header with the text "Table of Contents" (case-blind), and
  • generates a new table of contents for the document.

It writes the table of contents to standard output. You can then copy that text and replace the existing table of contents in the document.

Install mdtoc.py as follows, to make it easier:

$ cp mdtoc.py /usr/local/bin
$ chmod 755 /usr/local/bin/mdtoc.py

Obviously, you can use any directory you want, as long as it's in your path.

Note that mdtoc.py is pretty simple-minded.

  • It only handles the # header, ## header, etc., style of Markdown heading. (It doesn't grok underlined headings.)
  • It insists that the first "#" of a heading be in column 0.

One workflow, on the Mac, is:

  1. Delete the existing table of contents in the source document (but leaving the # Table of Contents heading.
  2. Run mdtoc doc | pbcopy to generate the table of contents and copy it to the Mac clipboard.
  3. Paste into the doc.
  4. Check the doc into Git and push it to the repo.

(Obviously, this only works when you're editing the doc on your local machine, in a checked-out version of the wiki.)

Clone this wiki locally