Skip to content

Commit a470894

Browse files
authored
Create hyperlinks for pretty, Markdown, reStructuredText and HTML output (#243)
2 parents 6a7a2af + 92ddf0e commit a470894

File tree

4 files changed

+83
-68
lines changed

4 files changed

+83
-68
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dynamic = [ "version" ]
3838
dependencies = [
3939
"httpx>=0.19",
4040
"platformdirs",
41-
"prettytable>=3.12",
41+
"prettytable>=3.16",
4242
"pytablewriter[html]>=0.63",
4343
"python-dateutil",
4444
"python-slugify",

src/norwegianblue/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def norwegianblue(
9595
if color != "no" and format != "yaml":
9696
data = _colourify(data, is_html=format == "html")
9797

98+
if format in ("pretty", "markdown", "rst", "html"):
99+
data = linkify(data, format)
100+
98101
output = _tabulate(data, format, color, product if show_title else None)
99102
logging.info("")
100103

@@ -104,6 +107,27 @@ def norwegianblue(
104107
return output
105108

106109

110+
def linkify(data: list[dict], format_: str) -> list[dict]:
111+
"""If a cycle has a link, add a hyperlink and remove the link column"""
112+
for cycle in data:
113+
if "link" in cycle:
114+
if cycle["link"]:
115+
if format_ == "pretty":
116+
cycle["cycle"] = (
117+
f"\033]8;;{cycle['link']}\033\\{cycle['cycle']}\033]8;;\033\\"
118+
)
119+
elif format_ == "markdown":
120+
cycle["cycle"] = f"[{cycle['cycle']}]({cycle['link']})"
121+
elif format_ == "rst":
122+
cycle["cycle"] = f"`{cycle['cycle']} <{cycle['link']}>`__"
123+
elif format_ == "html":
124+
cycle["cycle"] = f'<a href="{cycle["link"]}">{cycle["cycle"]}</a>'
125+
126+
cycle.pop("link")
127+
128+
return data
129+
130+
107131
@cache
108132
def suggest_product(product: str) -> str:
109133
import difflib

0 commit comments

Comments
 (0)