mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-05-31 16:47:11 +08:00
[Docs] Fix titles for multi-file examples that are rendered in the docs (#23573)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
parent
3ecbb14b81
commit
bfc1edc9f5
@ -70,6 +70,10 @@ class Example:
|
|||||||
self.other_files = self.determine_other_files()
|
self.other_files = self.determine_other_files()
|
||||||
self.title = self.determine_title()
|
self.title = self.determine_title()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_code(self) -> bool:
|
||||||
|
return self.main_file.suffix != ".md"
|
||||||
|
|
||||||
def determine_main_file(self) -> Path:
|
def determine_main_file(self) -> Path:
|
||||||
"""
|
"""
|
||||||
Determines the main file in the given path.
|
Determines the main file in the given path.
|
||||||
@ -101,6 +105,12 @@ class Example:
|
|||||||
return [file for file in self.path.rglob("*") if is_other_file(file)]
|
return [file for file in self.path.rglob("*") if is_other_file(file)]
|
||||||
|
|
||||||
def determine_title(self) -> str:
|
def determine_title(self) -> str:
|
||||||
|
if not self.is_code:
|
||||||
|
with open(self.main_file) as f:
|
||||||
|
first_line = f.readline().strip()
|
||||||
|
match = re.match(r'^#\s+(?P<title>.+)$', first_line)
|
||||||
|
if match:
|
||||||
|
return match.group('title')
|
||||||
return fix_case(self.path.stem.replace("_", " ").title())
|
return fix_case(self.path.stem.replace("_", " ").title())
|
||||||
|
|
||||||
def generate(self) -> str:
|
def generate(self) -> str:
|
||||||
@ -110,11 +120,13 @@ class Example:
|
|||||||
# Use long code fence to avoid issues with
|
# Use long code fence to avoid issues with
|
||||||
# included files containing code fences too
|
# included files containing code fences too
|
||||||
code_fence = "``````"
|
code_fence = "``````"
|
||||||
is_code = self.main_file.suffix != ".md"
|
# Skip the title from md snippets as it's been included above
|
||||||
if is_code:
|
start_line = 2
|
||||||
|
if self.is_code:
|
||||||
content += f"{code_fence}{self.main_file.suffix[1:]}\n"
|
content += f"{code_fence}{self.main_file.suffix[1:]}\n"
|
||||||
content += f'--8<-- "{self.main_file}"\n'
|
start_line = 1
|
||||||
if is_code:
|
content += f'--8<-- "{self.main_file}:{start_line}"\n'
|
||||||
|
if self.is_code:
|
||||||
content += f"{code_fence}\n"
|
content += f"{code_fence}\n"
|
||||||
content += "\n"
|
content += "\n"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user