Skip to content

Instantly share code, notes, and snippets.

@lmacken
Created February 21, 2012 19:04
Show Gist options
  • Save lmacken/1878192 to your computer and use it in GitHub Desktop.
Save lmacken/1878192 to your computer and use it in GitHub Desktop.
linkify.py - Turns URLs into links
#!/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