Skip to content

Instantly share code, notes, and snippets.

@ofZach
Last active August 29, 2015 13:56
Show Gist options
  • Save ofZach/8816529 to your computer and use it in GitHub Desktop.
Save ofZach/8816529 to your computer and use it in GitHub Desktop.
ruby to make markdown links a href target blank links. sort of doesn't work with link URLs that have () in them -- like some wikipedia urls that disambiguate. also seems to convert images inadvertently as well as markdown links since they have a similar-ish format.
File.open('test.txt', 'r+') do |f|
out = ""
f.each do |line|
out << line.gsub(/\[([^\]]+)\]\(([^)]+)\)/, '<a target="_blank" href="\2">\1</a>')
end
f.pos = 0
f.print out
f.truncate(f.pos)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment