File: generate_toc.rb

package info (click to toggle)
jabref 3.8.1%2Bds-3%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,336 kB
  • sloc: java: 114,114; xml: 3,985; python: 283; sh: 282; perl: 200; ruby: 22; makefile: 6
file content (15 lines) | stat: -rw-r--r-- 507 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env ruby

# Source: https://gist.github.com/albertodebortoli/9310424
# Via: http://stackoverflow.com/a/22131019/873282

File.open("Code-Howtos.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(" ", "-").gsub('"',"").downcase
    puts "  " * (line.count("#")-1) + "* [#{title}](\##{href})"
  end
end