A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Docs] Enable relative links in examples to function when rendered in the docs (#24041)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Harry Mellor committed
Sep 10, 2025 at 05:40 UTC
e40827280b225bf0a0797cc9842fc3cdfea8ebdf
1 file changed
+36
-7
docs/mkdocs/hooks/generate_examples.py
+36
-7
@@ -114,6 +114,33 @@ class Example:
114
return match.group('title')
115
return fix_case(self.path.stem.replace("_", " ").title())
116
117
+ def fix_relative_links(self, content: str) -> str:
118
+ """
119
+ Fix relative links in markdown content by converting them to gh-file
120
+ format.
121
+
122
+ Args:
123
+ content (str): The markdown content to process
124
+
125
+ Returns:
126
+ str: Content with relative links converted to gh-file format
127
+ """
128
+ # Regex to match markdown links [text](relative_path)
129
+ # This matches links that don't start with http, https, ftp, or #
130
+ link_pattern = r'\[([^\]]*)\]\((?!(?:https?|ftp)://|#)([^)]+)\)'
131
+
132
+ def replace_link(match):
133
+ link_text = match.group(1)
134
+ relative_path = match.group(2)
135
+
136
+ # Make relative to repo root
137
+ gh_file = (self.main_file.parent / relative_path).resolve()
138
+ gh_file = gh_file.relative_to(ROOT_DIR)
139
+
140
+ return f'[{link_text}](gh-file:{gh_file})'
141
+
142
+ return re.sub(link_pattern, replace_link, content)
143
+
144
def generate(self) -> str:
145
content = f"# {self.title}\n\n"
146
content += f"Source <gh-file:{self.path.relative_to(ROOT_DIR)}>.\n\n"
@@ -121,14 +148,16 @@ class Example:
148
# Use long code fence to avoid issues with
149
# included files containing code fences too
150
code_fence = "``````"
124
- # Skip the title from md snippets as it's been included above
125
- start_line = 2
126
- if self.is_code:
127
- content += f"{code_fence}{self.main_file.suffix[1:]}\n"
128
- start_line = 1
129
- content += f'--8<-- "{self.main_file}:{start_line}"\n'
151
+
152
if self.is_code:
131
- content += f"{code_fence}\n"
153
+ content += (f"{code_fence}{self.main_file.suffix[1:]}\n"
154
+ f'--8<-- "{self.main_file}"\n'
155
+ f"{code_fence}\n")
156
+ else:
157
+ with open(self.main_file) as f:
158
+ # Skip the title from md snippets as it's been included above
159
+ main_content = f.readlines()[1:]
160
+ content += self.fix_relative_links("".join(main_content))
161
content += "\n"
162
163
if not self.other_files: