Created
February 21, 2012 19:04
-
-
Save lmacken/1878192 to your computer and use it in GitHub Desktop.
linkify.py - Turns URLs into links
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
#!/usr/bin/env python | |
# linkify.py - Turns URLs into links. | |
# | |
# Using on a file: | |
# | |
# $ linkify.py <filename> | |
# <a href="http://lewk.org">http://lewk.org</a> | |
# | |
# Using within a pipeline: | |
# | |
# $ echo 'http://lewk.org' | linkify.py | |
# <a href="http://lewk.org">http://lewk.org</a> | |
# | |
# Author: Luke Macken <[email protected]> | |
# License: GPLv3 | |
import re, fileinput | |
for line in fileinput.input(): | |
for match in re.findall(r'https?:\/\/\S+', line): | |
line = line.replace(match, '<a href="%s">%s</a>' % (match, match)) | |
print line, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment