mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-06-28 07:20:21 +08:00
refactor(ci): enhance URL extraction
This commit is contained in:
parent
8d087c04eb
commit
bab7a2165a
@ -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: 
|
||||
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}'")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user