refactor(ci): enhance URL extraction

This commit is contained in:
Bjorn Lammers 2025-04-25 23:52:26 +02:00
parent 8d087c04eb
commit bab7a2165a

View File

@ -213,10 +213,19 @@ def mapListFrom(input: dict, label: str) -> list:
return []
return list(map(str.strip, stringList.split(",")))
def mapUrlFromMarkdownImage(input: dict, label: str) -> re.Match[str]:
markdown = mapFromRequired(input, label)
try:
return re.match(r"!\[[^\]]+\]\((https:[^\)]+)\)", markdown)[1]
except IndexError:
raise ValueError(f"Invalid markdown image: '{markdown}'")
def mapUrlFromMarkdownImage(input: dict, label: str) -> str:
markdown_or_html = mapFromRequired(input, label)
# Try Markdown format: ![alt](url)
markdown_match = re.match(r"!\[[^\]]*\]\((https:[^\)]+)\)", markdown_or_html)
if markdown_match:
return markdown_match[1]
# Try HTML format: <img src="url" ...>
html_match = re.search(r"<img[^>]+src=\"(https:[^\"]+)\"", markdown_or_html)
if html_match:
return html_match[1]
# If neither matches
raise ValueError(f"Could not extract URL from '{label}'. Expected Markdown image or HTML img tag, but got: '{markdown_or_html}'")