Last active
August 29, 2015 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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