Skip to content

Instantly share code, notes, and snippets.

@TFaga
Created August 13, 2017 09:42
Show Gist options
  • Save TFaga/f17f43feba619799391100a9927e605e to your computer and use it in GitHub Desktop.
Save TFaga/f17f43feba619799391100a9927e605e to your computer and use it in GitHub Desktop.
Markdown table of content creator
#!/usr/bin/env ruby
File.open("spec-payment-system-v1.md", 'r') do |f|
f.each_line do |line|
forbidden_words = ['Table of contents', 'define', 'pragma']
next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ }
title = line.gsub("#", "").strip
href = title.gsub(" ", "-").downcase
puts " " * (line.count("#")-1) + "* #{title}"
#puts " " * (line.count("#")-1) + "* [#{title}](\##{href})"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment