Skip to content

Commit a15672f

Browse files
Documentation: fixed images in main readme
1 parent 1c7e902 commit a15672f

File tree

2 files changed

+72
-49
lines changed

2 files changed

+72
-49
lines changed

Doc/md_filter.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44

5+
56
def compute_page_id(input_filepath):
67
# Determine the directory of this script.
78
script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -16,6 +17,7 @@ def compute_page_id(input_filepath):
1617
page_id = rel_path_no_ext.replace(os.sep, "_")
1718
return page_id
1819

20+
1921
def replace_special_symbols(text):
2022
# Define your symbol mappings using Unicode escape sequences.
2123
replacements = {
@@ -26,6 +28,23 @@ def replace_special_symbols(text):
2628
text = text.replace(key, value)
2729
return text
2830

31+
32+
def replace_github_blob_urls(text):
33+
"""
34+
Replaces '/blob/' with '/raw/' in GitHub image URLs.
35+
36+
For example:
37+
https://github.com/DiligentGraphics/DiligentSamples/blob/master/...
38+
becomes:
39+
https://github.com/DiligentGraphics/DiligentSamples/raw/master/...
40+
"""
41+
# This regex looks for URLs starting with https://github.com/
42+
# that have the structure: /<user>/<repo>/blob/<rest>
43+
pattern = r'(https://github\.com/[^/]+/[^/]+/)(blob)/(.*?)'
44+
# Replace the matched 'blob' with 'raw'
45+
return re.sub(pattern, r'\1raw/\3', text)
46+
47+
2948
def process_content(input_filepath, lines):
3049
page_id = compute_page_id(input_filepath)
3150
output_lines = []
@@ -36,6 +55,9 @@ def process_content(input_filepath, lines):
3655
# Apply symbol replacement for every line.
3756
line = replace_special_symbols(line)
3857

58+
# Fix image URLs.
59+
line = replace_github_blob_urls(line)
60+
3961
# Look for the first non-empty line that starts with a Markdown header.
4062
if not header_replaced and line.strip():
4163
match = header_regex.match(line)
@@ -46,6 +68,7 @@ def process_content(input_filepath, lines):
4668
header_replaced = True
4769
continue
4870
output_lines.append(line)
71+
4972
return output_lines
5073

5174
def main():

0 commit comments

Comments
 (0)