Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fileName = ARGV[0]
- fileName = "README.md" if !fileName
- #File.write('test.log',"**Table of Contents**" + "\n")
- toc = "**Table of Contents**" + "\n"
- File.open(fileName, 'r+') do |f|
- inside_code_snippet = false
- f.each_line do |line|
- forbidden_words = ['Table of contents', 'define', 'pragma']
- inside_code_snippet = !inside_code_snippet if line.start_with?('```')
- next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ } || inside_code_snippet
- title = line.gsub("#", "").strip
- href = title.gsub(" ", "-").downcase
- toc = toc + " " * (line.count("#")-1) + "* [#{title}](\##{href})" + "\n"
- end
- puts toc + "\n"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement