TOC generator for Markdown files

As much as I love how MultiMarkdown (MMD) auto-generates a table-of-contents just by adding the {{TOC}} command to our Markdown files, its implementation in MMD version 6 still has a drawback. This drawback concerns links that are included in the headings’ text (inserted manually or generated by DEVONthink’s auto-WikiLinks option), as they break and split the TOC-link entries. I further describe that problem on my blog. To overcome this miss-behavior, I’ve written an AppleScript, which generates a TOC and adds it to the Markdown file, using a Python script:


The disadvantage of my solution is, that it doesn’t auto-update the TOC, i.e., after every change to your headings you have to re-run the AppleScript. However, it solves the TOC-link problem of MMD version 6.

You can find the script including the Python files and an additional script to remove the TOC on GitHub. Please let me know if you notice any bugs or flaws by reporting them in the issue section of the repository. Please, also read the warning carefully and create backups of your files before applying the script.

1 Like

Update: I just discovered that encapsulating auto-WikiLinks in headings by angle brackets (<,>) also bypasses the MMD TOC-link problem. E.g., in my example from above, I would have to encapsulate “Some Test File” (which is an auto-WikiLink to a file of the same name): “<Some Test File>” – and the TOC-links generated by the {{TOC}} command will still work :ok_hand:

Interesting…
I’m curious, why not just use the square bracket syntax for WikiLinks instead. :thinking:

btw, the bypass with the angle brackets also works in DTTG :+1:While this seems to be a trivial statement, other solutions to suppress auto-WikiLinks in headings by, e.g., placing a soft-hyphen somewhere in the auto-linked name/alias only worked in the desktop app, but not in DTTG (clicking on the corresponding TOC-link became effectless).

That’s a good point. Actually, I’ve really fallen in love with the auto-WikiLinks solutions and it became an essential part in my Zettelkasten workflow. I like how unseen connections between my notes emerge while I write a new note or add something to an existing one. Using the square bracket syntax, however, would require knowledge about the notes that relate to each other and spontaneous connections would become less likely.

I like how unseen connections between my notes emerge while I write a new note or add something to an existing one.

Gotcha… so the WikiLinking surfaces existing things you may not have on your mind, similar to how the See Also inspector can. That’s an interesting take on it. :slight_smile:

1 Like