Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a table of contents for Ulysses markdown
#!/usr/bin/env ruby
toc = "# Table of Contents\n"
newmd = ""
ARGF.each_line do |line|
newmd << line
next if !line.start_with?("#")
heading = line.gsub("#", "").strip
href = heading.gsub(" ", "-").downcase
newmd << "<a name=\"#{href}\"></a>\n"
toc << "\t" * (line.count("#")-1) + "- [#{heading}](\##{href})\n"
puts toc + "\n" + newmd

This comment has been minimized.

Copy link
Owner Author

JenniferMack commented Apr 1, 2015

Usage: cat | md-toc.rb >


This comment has been minimized.

Copy link

Akela2606 commented Apr 8, 2019

thanks for sharing this script.
Sorry to bother you here but I don't know how else I could contact you on this site.
Do you know how I can use it with the latest version of Ulysses?
I cannot find any .md file in my Ulysses folder...
I am going crazy here, trying to get a table of contents for a poetry book with about 120 poems... :-(
Thanks a lot for your help.
Kindest regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.