MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / generate_markdown_chapter

Function generate_markdown_chapter

build_ebook.py:106–134  ·  view source on GitHub ↗
(
    chapter: MarkdownChapter, converted_image_dir: Path
)

Source from the content-addressed store, hash-verified

104
105
106def generate_markdown_chapter(
107 chapter: MarkdownChapter, converted_image_dir: Path
108) -> str:
109 contents = f"# {chapter.title}\n\n{chapter.contents}"
110
111 # Adjust titles based on depth of chapter itself
112 if chapter.depth > 0:
113
114 def adjust_title_depth(match: Match) -> str:
115 return ("#" * chapter.depth) + match.group(0)
116
117 contents = re.sub(r"#+ ", adjust_title_depth, contents)
118
119 # Fix image links
120 contents = contents.replace("/images/", f"{converted_image_dir.as_posix()}/")
121 contents = contents.replace(".svg", ".png")
122
123 # Fix remaining relative links
124 contents = contents.replace("(/code", "(https://vulkan-tutorial.com/code")
125 contents = contents.replace("(/resources", "(https://vulkan-tutorial.com/resources")
126
127 # Fix chapter references
128 def fix_chapter_reference(match: Match) -> str:
129 target = match.group(1).lower().replace("_", "-").split("/")[-1]
130 return f"](#{target})"
131
132 contents = re.sub(r"\]\(!([^)]+)\)", fix_chapter_reference, contents)
133
134 return contents
135
136
137def compile_full_markdown(

Callers 1

compile_full_markdownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected