Created
November 12, 2015 14:06
-
-
Save nmeylan/b15e65d6d510ff91fc2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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