Skip to content

Instantly share code, notes, and snippets.

@nmeylan
Created November 12, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmeylan/b15e65d6d510ff91fc2d to your computer and use it in GitHub Desktop.
Save nmeylan/b15e65d6d510ff91fc2d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
FORBIDDEN_WORDS = ['Table of contents', 'define', 'pragma'].freeze
def should_skip_line?(line)
!line.start_with?("#") || FORBIDDEN_WORDS.any? { |word| line =~ /#{word}/ }
end
File.open(ARGV[0], 'r') do |f|
in_code_block = false
f.each_line do |line|
in_code_block = !in_code_block if line =~ (/```/)
next if should_skip_line?(line) || in_code_block
title = line.tr("#", "").strip
href = title.tr(" ", "-").downcase
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