Skip to content

Commit 6b04d17

Browse files
sync-wiki to process img<> tags
1 parent 97f4637 commit 6b04d17

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

.github/scripts/sync-wiki.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def load_mapping():
2424
def convert_relative_links(content, source_path):
2525
"""Convert relative links in markdown content to absolute URLs."""
2626
# Find markdown links with regex pattern [text](url)
27-
pattern = r'\[([^\]]+)\]\(([^)]+)\)'
27+
md_pattern = r'\[([^\]]+)\]\(([^)]+)\)'
28+
29+
# Find HTML img tags
30+
img_pattern = r'<img\s+src=[\'"]([^\'"]+)[\'"]'
2831

2932
def replace_link(match):
3033
link_text = match.group(1)
@@ -51,8 +54,37 @@ def replace_link(match):
5154
github_url = f"{REPO_URL}/blob/main{abs_path}"
5255
return f"[{link_text}]({github_url})"
5356

54-
# Replace all links
55-
return re.sub(pattern, replace_link, content)
57+
def replace_img_src(match):
58+
img_src = match.group(1)
59+
60+
# Skip if already absolute URL
61+
if img_src.startswith(('http://', 'https://')):
62+
return match.group(0)
63+
64+
# Get the directory of the source file
65+
source_dir = os.path.dirname(source_path)
66+
67+
# Create absolute path from repository root
68+
if img_src.startswith('/'):
69+
# If link starts with /, it's already relative to repo root
70+
abs_path = img_src
71+
else:
72+
# Otherwise, it's relative to the file location
73+
abs_path = os.path.normpath(os.path.join(source_dir, img_src))
74+
if not abs_path.startswith('/'):
75+
abs_path = '/' + abs_path
76+
77+
# Convert to GitHub URL (use raw URL for images)
78+
github_url = f"{REPO_URL}/raw/main{abs_path}"
79+
return f'<img src="{github_url}"'
80+
81+
# Replace all markdown links
82+
content = re.sub(md_pattern, replace_link, content)
83+
84+
# Replace all img src tags
85+
content = re.sub(img_pattern, replace_img_src, content)
86+
87+
return content
5688

5789
def process_file(source_file, target_wiki_page):
5890
"""Process a markdown file and copy its contents to a wiki page."""

benchmarks/rotatingDrum/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This benchmark compares the performance of phasicFlow with a well-stablished com
1616
<div align="center">
1717
<img src="./images/phasicFlow_snapshot.png"/>
1818
<div align="center">
19-
<p>Figure 2. phasicFlow simulation snapshot</p>
19+
<p>Figure 2. phasicFlow simulation snapshot and visualized using Paraview</p>
2020
</div>
2121
</div>
2222

0 commit comments

Comments
 (0)