Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. fileName = ARGV[0]
  2. fileName = "README.md" if !fileName
  3.  
  4. #File.write('test.log',"**Table of Contents**" + "\n")
  5. toc = "**Table of Contents**" + "\n"
  6.  
  7. File.open(fileName, 'r+') do |f|
  8. inside_code_snippet = false
  9. f.each_line do |line|
  10. forbidden_words = ['Table of contents', 'define', 'pragma']
  11. inside_code_snippet = !inside_code_snippet if line.start_with?('```')
  12. next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ } || inside_code_snippet
  13.  
  14. title = line.gsub("#", "").strip
  15. href = title.gsub(" ", "-").downcase
  16. toc = toc + " " * (line.count("#")-1) + "* [#{title}](\##{href})" + "\n"
  17. end
  18. puts toc + "\n"
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement