Skip to content

Commit 55c2aaa

Browse files
committed
fix: Correct image URL generation and add YouTube link handling in Markdown to BBCode conversion
1 parent 2b231d0 commit 55c2aaa

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

markdown_to_bbcode.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ def replace_headers(match):
8282
def replace_images(match):
8383
image_url = match.group(1)
8484
if repo_name and not re.match(r'^https?://', image_url):
85-
absolute_url = f"https://raw.githubusercontent.com/{repo_name}/refs/heads/main/{relative_path}/{image_url}"
85+
absolute_url = f"raw.githubusercontent.com/{repo_name}/refs/heads/main/{relative_path}/{image_url}"
8686
absolute_url = absolute_url.replace('//', '/')
87+
absolute_url = f"https://{absolute_url}"
8788
if bbcode_type == 'egosoft':
8889
return f"[spoiler][img]{absolute_url}[/img][/spoiler]"
8990
else:
@@ -114,7 +115,10 @@ def replace_block_code(match):
114115
# Convert [text](url) to [url=url]text[/url]
115116
def replace_links(match):
116117
link_text, link_url = match.groups()
117-
if repo_name and not re.match(r'^https?://', link_url):
118+
if bbcode_type == 'steam' and 'youtube.com/watch?v=' in link_url:
119+
video_id = re.search(r'v=([^&]+)', link_url).group(1)
120+
return f"[previewyoutube={video_id};full][/previewyoutube]"
121+
elif repo_name and not re.match(r'^https?://', link_url):
118122
absolute_url = f"https://github.com/{repo_name}/raw/main/{relative_path}/{link_url}"
119123
return f"[url={absolute_url}]{link_text}[/url]"
120124
else:

0 commit comments

Comments
 (0)