Skip to content

Instantly share code, notes, and snippets.

@pcreux
Created June 2, 2011 00:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pcreux/1003649 to your computer and use it in GitHub Desktop.
Save pcreux/1003649 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
str = File.read('CHANGELOG.md')
people = []
str.each_line do |l|
found = l.match(/\[@(\w+)\]\(([\w:\/.]+)\)/)
if found
user = found[1]
url = found[2]
people << [user, url] unless people.include? [user, url]
end
end
people.sort! { |p1, p2| p1.first <=> p2.first }
puts str.gsub(/\[@(\w+)\]\(([\w:\/.]+)\)/, '[@\1][]')
puts ""
people.each do |user, url|
puts "[@#{user}]: #{url}"
end
@rymai
Copy link

rymai commented Jun 2, 2011

Sweet!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment