[Docs] Convert rST to MyST (Markdown) (#11145)
Signed-off-by: Rafael Vasquez <rafvasq21@gmail.com>
This commit is contained in:
@@ -15,18 +15,12 @@ def fix_case(text: str) -> str:
|
||||
return text
|
||||
|
||||
|
||||
def underline(title: str, character: str = "=") -> str:
|
||||
return f"{title}\n{character * len(title)}"
|
||||
|
||||
|
||||
def generate_title(filename: str) -> str:
|
||||
# Turn filename into a title
|
||||
title = filename.replace("_", " ").title()
|
||||
# Handle acronyms and names
|
||||
title = fix_case(title)
|
||||
# Underline title
|
||||
title = underline(title)
|
||||
return title
|
||||
return f"# {title}"
|
||||
|
||||
|
||||
def generate_examples():
|
||||
@@ -38,7 +32,7 @@ def generate_examples():
|
||||
|
||||
# Destination paths
|
||||
doc_dir = root_dir / "docs/source/getting_started/examples"
|
||||
doc_paths = [doc_dir / f"{path.stem}.rst" for path in script_paths]
|
||||
doc_paths = [doc_dir / f"{path.stem}.md" for path in script_paths]
|
||||
|
||||
# Generate the example docs for each example script
|
||||
for script_path, doc_path in zip(script_paths, doc_paths):
|
||||
@@ -46,16 +40,16 @@ def generate_examples():
|
||||
# Make script_path relative to doc_path and call it include_path
|
||||
include_path = '../../../..' / script_path.relative_to(root_dir)
|
||||
content = (f"{generate_title(doc_path.stem)}\n\n"
|
||||
f"Source {script_url}.\n\n"
|
||||
f".. literalinclude:: {include_path}\n"
|
||||
" :language: python\n"
|
||||
" :linenos:\n")
|
||||
f"Source: <{script_url}>.\n\n"
|
||||
f"```{{literalinclude}} {include_path}\n"
|
||||
":language: python\n"
|
||||
":linenos:\n```")
|
||||
with open(doc_path, "w+") as f:
|
||||
f.write(content)
|
||||
|
||||
# Generate the toctree for the example scripts
|
||||
with open(doc_dir / "examples_index.template.rst") as f:
|
||||
with open(doc_dir / "examples_index.template.md") as f:
|
||||
examples_index = f.read()
|
||||
with open(doc_dir / "examples_index.rst", "w+") as f:
|
||||
example_docs = "\n ".join(path.stem for path in script_paths)
|
||||
with open(doc_dir / "examples_index.md", "w+") as f:
|
||||
example_docs = "\n".join(path.stem + ".md" for path in script_paths)
|
||||
f.write(examples_index.replace(r"%EXAMPLE_DOCS%", example_docs))
|
||||
|
||||
Reference in New Issue
Block a user