Files
clan-core/pkgs/clan-cli/clan_cli/hyperlink.py
Johannes Kirschbauer 90b1033870 docs: unify markdown files with documentation titles
This is preparational work to reduce the surface are of the different mappings

We want to reduce the following:

/guides/secrets.md -> Guides/getting started/How to use flakes with sops -> with '# Secrets Management'

- Title
- URI
- Filepath

should follow a stricter pattern to make it easy to maintain
2025-10-03 16:08:20 +02:00

39 lines
1.0 KiB
Python

import sys
# Implementation of OSC8
def hyperlink(text: str, url: str) -> str:
"""Generate OSC8 escape sequence for hyperlinks.
Args:
url (str): The URL to link to.
text (str): The text to display.
Returns:
str: The formatted string with an embedded hyperlink.
"""
esc = "\033"
return f"{esc}]8;;{url}{esc}\\{text}{esc}]8;;{esc}\\"
def hyperlink_same_text_and_url(url: str) -> str:
"""Keep the description and the link the same to support legacy terminals."""
return hyperlink(url, url)
def help_hyperlink(description: str, url: str) -> str:
"""Keep the description and the link the same to support legacy terminals."""
if sys.argv[0].__contains__("docs.py"):
return docs_hyperlink(description, url)
return hyperlink_same_text_and_url(url)
def docs_hyperlink(description: str, url: str) -> str:
"""Returns a markdown hyperlink"""
url = url.replace("https://docs.clan.lol", "/")
url = url.replace("index.html", "index")
url += ".md"
return f"[{description}]({url})"