Skip to content

Instantly share code, notes, and snippets.

@gautiermichelin
Forked from JenniferMack/md-toc.rb
Created July 7, 2015 06:53
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 gautiermichelin/a56e510ee5414e41cf02 to your computer and use it in GitHub Desktop.
Save gautiermichelin/a56e510ee5414e41cf02 to your computer and use it in GitHub Desktop.
Traduction en français
#!/usr/bin/env ruby
toc = "# Sommaire\n"
newmd = ""
ARGF.each_line do |line|
newmd << line
next if !line.start_with?("#")
heading = line.gsub("#", "").strip
href = heading.gsub(" ", "-").downcase
newmd << "<a name=\"#{href}\"></a>\n"
toc << "\t" * (line.count("#")-1) + "- [#{heading}](\##{href})\n"
end
puts toc + "\n" + newmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment