uses regex to detect a common URL pattern and converts to href tag in format.
(x, format)
| 1952 | |
| 1953 | |
| 1954 | def _render_href(x, format): |
| 1955 | """uses regex to detect a common URL pattern and converts to href tag in format.""" |
| 1956 | if isinstance(x, str): |
| 1957 | if format == "html": |
| 1958 | href = '<a href="{0}" target="_blank">{0}</a>' |
| 1959 | elif format == "latex": |
| 1960 | href = r"\href{{{0}}}{{{0}}}" |
| 1961 | else: |
| 1962 | raise ValueError("``hyperlinks`` format can only be 'html' or 'latex'") |
| 1963 | pat = r"((http|ftp)s?:\/\/|www.)[\w/\-?=%.:@]+\.[\w/\-&?=%.,':;~!@#$*()\[\]]+" |
| 1964 | return re.sub(pat, lambda m: href.format(m.group(0)), x) |
| 1965 | return x |
| 1966 | |
| 1967 | |
| 1968 | def _maybe_wrap_formatter( |
no test coverage detected