Skip to content

Commit 3da8d07

Browse files
committed
Formatting
1 parent e935a35 commit 3da8d07

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
*.html
22
ads.txt
33

4+
**/_out/*
5+
**/.vscode/*
46
.DS_Store
57
build_ebook.log
68
temp_ebook.md
7-
**/_out/*

build_ebook.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class VTLogger:
1313
"""A logger"""
14+
1415
def __init__(self, filename:str, log_to_file:bool=True) -> None:
1516
if log_to_file is True:
1617
self.log_file = open(filename, "w", encoding="utf-8")
@@ -45,10 +46,13 @@ def _log(self, message: str, no_print:bool=False) -> None:
4546
if self.log_file is not None:
4647
self.log_file.write(f"{message}\n")
4748

49+
4850
class VTEMarkdownFile:
4951
"""Markdown file."""
5052

51-
def __init__(self, content: str, depth: int, prefix: str, title: str) -> None:
53+
def __init__(
54+
self, content: str, depth: int, prefix: str, title: str
55+
) -> None:
5256
self.content: str = content
5357
self.depth: str = depth
5458
self.prefix: str = prefix
@@ -66,13 +70,16 @@ def __str__(self) -> str:
6670
f" title: '{self.title}', content: '{self.content}'>"
6771
)
6872

73+
6974
class VTEBookBuilder:
7075
"""A 'Markdown' to 'epub' and 'pdf' converter."""
7176

7277
def __init__(self, logger: VTLogger) -> None:
7378
self.log = logger
7479

75-
def build_pdf_book(self, language: str, markdown_filepath: pathlib.Path) -> None:
80+
def build_pdf_book(
81+
self, language: str, markdown_filepath: pathlib.Path
82+
) -> None:
7683
"""Builds a pdf file"""
7784

7885
self.log.info("Building 'pdf'...")
@@ -111,7 +118,9 @@ def build_pdf_book(self, language: str, markdown_filepath: pathlib.Path) -> None
111118

112119
raise RuntimeError from error
113120

114-
def build_epub_book(self, language: str, markdown_filepath: pathlib.Path) -> None:
121+
def build_epub_book(
122+
self, language: str, markdown_filepath: pathlib.Path
123+
) -> None:
115124
"""Buids a epub file"""
116125

117126
self.log.info("Building 'epub'...")
@@ -156,13 +165,17 @@ def convert_svg_to_png(self, images_folder: str) -> list[pathlib.Path]:
156165
pngs.append(new_path)
157166
except FileNotFoundError as error:
158167
self.log.error(error)
159-
self.log.warning("Install 'Inkscape' (https://www.inkscape.org)!")
168+
self.log.warning(
169+
"Install 'Inkscape' (https://www.inkscape.org)!"
170+
)
160171

161172
raise RuntimeError from error
162173

163174
return pngs
164175

165-
def generate_joined_markdown(self, language: str, output_filename: pathlib.Path) -> None:
176+
def generate_joined_markdown(
177+
self, language: str, output_filename: pathlib.Path
178+
) -> None:
166179
"""Processes the markdown sources and produces a joined file."""
167180

168181
self.log.info(
@@ -202,7 +215,11 @@ def repl_hash(match):
202215
content = re.sub(r"\.svg", ".png", content)
203216

204217
# Fix remaining relative links (e.g. code files).
205-
content = re.sub(r"\]\(\/", "](https://vulkan-tutorial.com/", content)
218+
content = re.sub(
219+
r"\]\(\/",
220+
"](https://vulkan-tutorial.com/",
221+
content
222+
)
206223

207224
# Fix chapter references.
208225
def repl(match):
@@ -242,7 +259,9 @@ def _collect_markdown_files_from_source(
242259

243260
title = " ".join(title_tokens[1:])
244261

245-
markdown_files.append(VTEMarkdownFile("", current_depth, prefix, title))
262+
markdown_files.append(
263+
VTEMarkdownFile("", current_depth, prefix, title)
264+
)
246265

247266
self._collect_markdown_files_from_source(
248267
entry,
@@ -256,7 +275,9 @@ def _collect_markdown_files_from_source(
256275

257276
with open(entry, "r", encoding="utf-8") as file:
258277
content = file.read()
259-
markdown_files.append(VTEMarkdownFile(content, current_depth, prefix, title))
278+
markdown_files.append(
279+
VTEMarkdownFile(content, current_depth, prefix, title)
280+
)
260281

261282
return markdown_files
262283

@@ -278,10 +299,15 @@ def _collect_markdown_files_from_source(
278299
generated_pngs = eBookBuilder.convert_svg_to_png("./images")
279300

280301
LANGUAGES = [ "en", "fr" ]
281-
OUTPUT_MARKDOWN_FILEPATH = pathlib.Path(f"{out_dir.as_posix()}/temp_ebook.md")
302+
OUTPUT_MARKDOWN_FILEPATH = pathlib.Path(
303+
f"{out_dir.as_posix()}/temp_ebook.md"
304+
)
282305

283306
for lang in LANGUAGES:
284-
eBookBuilder.generate_joined_markdown(f"./{lang}", OUTPUT_MARKDOWN_FILEPATH)
307+
eBookBuilder.generate_joined_markdown(
308+
f"./{lang}",
309+
OUTPUT_MARKDOWN_FILEPATH
310+
)
285311

286312
try:
287313
eBookBuilder.build_epub_book(lang, OUTPUT_MARKDOWN_FILEPATH)

0 commit comments

Comments
 (0)