Skip to content

Instantly share code, notes, and snippets.

@rymai
Forked from pcreux/awesomer.rb
Created June 2, 2011 00:29
Show Gist options
  • Save rymai/1003676 to your computer and use it in GitHub Desktop.
Save rymai/1003676 to your computer and use it in GitHub Desktop.
Convert markdown inline links to link definitions
# For https://github.com/guard/guard/blob/master/CHANGELOG.md
input, output, people = File.read('CHANGELOG.md'), "", {}
input.each_line do |line|
if found = line.match(/\[@(\w+)\]\(([\w:\/.]+)\)/)
user, url = found[1], found[2]
people[user] = url unless people.include?(user)
end
end
people = people.sort { |p1, p2| p1[0] <=> p2[0] }
output += input.gsub(/\[@(\w+)\]\(([\w:\/.]+)\)/, '[@\1][]')
output += "\n"
people.each do |user, url|
output += "[@#{user}]: #{url}\n"
end
puts output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment