diff --git a/pandas/core/format.py b/pandas/core/format.py
index 7b8a3161b5e05..5afc1cee5248e 100644
--- a/pandas/core/format.py
+++ b/pandas/core/format.py
@@ -6,6 +6,7 @@
from pandas.core.base import PandasObject
from pandas.core.common import adjoin, notnull
+from pandas.io.common import _is_url
from pandas.core.index import Index, MultiIndex, _ensure_index
from pandas import compat
from pandas.compat import(StringIO, lzip, range, map, zip, reduce, u,
@@ -861,8 +862,13 @@ def write_tr(self, line, indent=0, indent_delta=4, header=False,
self.write('
' % align, indent)
indent += indent_delta
+
for i, s in enumerate(line):
val_tag = tags.get(i, None)
+ if s and hasattr(s, 'lower'):
+ s = s.lstrip(' ')
+ if _is_url(s):
+ s = "%s"%(s, s)
if header or (self.bold_rows and i < nindex_levels):
self.write_th(s, indent, tags=val_tag)
else:
diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py
index 1dcdbf12a6b59..02ae8906b5c84 100644
--- a/pandas/tests/test_format.py
+++ b/pandas/tests/test_format.py
@@ -716,6 +716,35 @@ def test_to_html_multiindex_sparsify_false_multi_sparse(self):
"""
self.assertEqual(result, expected)
+
+ def test_to_html_with_hyperlinks(self):
+ df = DataFrame([[0,'http://pandas.pydata.org/', 'pydata.org']],columns=['foo', 'bar', None], index=lrange(1))
+ f = lambda x: 'a'[x]
+ result = df.to_html(formatters={'__index__': f})
+ #result = df.to_html()
+ expected = """\
+
+
+
+ |
+ foo |
+ bar |
+ None |
+
+
+
+
+ a |
+ 0 |
+ <a href="http://pandas.pydata.org/">http://pandas.pydata.org/</a> |
+ pydata.org |
+
+
+
"""
+ self.assertEqual(result, expected)
+
+
+
def test_to_html_multiindex_sparsify(self):
index = MultiIndex.from_arrays([[0, 0, 1, 1], [0, 1, 0, 1]],
names=['foo', None])