Skip to content

Commit 4a56ff9

Browse files
committed
Final cleanup
1 parent 0023334 commit 4a56ff9

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

build_ebook_v2.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# """Generates epub and pdf from sources."""
1+
#!/usr/bin/env python3
2+
3+
"""Generates epub and pdf from sources."""
24

35
import pathlib
46
import re
@@ -174,26 +176,19 @@ def generate_joined_markdown(self, language: str, output_filename: pathlib.Path)
174176

175177
temp_markdown: str = str()
176178

177-
# def repl_hash(match):
178-
# original_prefix = match.group(1)
179-
# additional_prefix: str = "#" * entry.depth
180-
181-
# return f"{original_prefix}{additional_prefix} "
182179

183180
def repl_hash(match):
181+
"""Calculates the proper `Markdown` heading depth (#)."""
184182
original_prefix = match.group(1)
185183
additional_prefix: str = "#" * entry.depth
186184

187185
return f"{original_prefix}{additional_prefix} "
188186

189187
for entry in md_files:
190188
# Add title.
191-
# header_prefix: str = "#" * entry.depth
192-
# content: str = f"#{header_prefix} {entry.title}\n\n"
193-
# content: str = '# ' + entry.title + '\n\n'
194189
content: str = f"# {entry.title}\n\n{entry.content}"
195190

196-
# Fix depth
191+
# Fix depth.
197192
if entry.depth > 0:
198193
content = re.sub(r"(#+) ", repl_hash, content)
199194

@@ -204,7 +199,7 @@ def repl_hash(match):
204199
# Fix remaining relative links (e.g. code files).
205200
content = re.sub(r'\]\(\/', '](https://vulkan-tutorial.com/', content)
206201

207-
# Fix chapter references
202+
# Fix chapter references.
208203
def repl(match):
209204
target = match.group(1)
210205
target = target.lower()
@@ -289,20 +284,20 @@ def _collect_markdown_files_from_source(
289284
except RuntimeError as runtimeError:
290285
log.error("Termininating...")
291286

292-
# Clean up
287+
# Clean up.
293288
if OUTPUT_MARKDOWN_FILEPATH.exists():
294289
OUTPUT_MARKDOWN_FILEPATH.unlink()
295290

296291
log.info("Cleaning up...")
297292

298-
# Clean up temporary files
293+
# Clean up temporary files.
299294
for png_path in generated_pngs:
300295
try:
301296
png_path.unlink()
302297
except FileNotFoundError as fileError:
303298
log.error(fileError)
304299

305-
# Comment out to view log file
300+
# Comment out to view log file.
306301
if out_dir.exists():
307302
shutil.rmtree(out_dir)
308303

0 commit comments

Comments
 (0)