Skip to content

Commit 0023334

Browse files
committed
Fixed title generation
1 parent 4aa87c0 commit 0023334

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

build_ebook_v2.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,28 @@ def generate_joined_markdown(self, language: str, output_filename: pathlib.Path)
174174

175175
temp_markdown: str = str()
176176

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} "
182+
183+
def repl_hash(match):
184+
original_prefix = match.group(1)
185+
additional_prefix: str = "#" * entry.depth
186+
187+
return f"{original_prefix}{additional_prefix} "
188+
177189
for entry in md_files:
178190
# Add title.
179-
content: str = '# ' + entry.title + '\n\n' + entry.content
191+
# header_prefix: str = "#" * entry.depth
192+
# content: str = f"#{header_prefix} {entry.title}\n\n"
193+
# content: str = '# ' + entry.title + '\n\n'
194+
content: str = f"# {entry.title}\n\n{entry.content}"
195+
196+
# Fix depth
197+
if entry.depth > 0:
198+
content = re.sub(r"(#+) ", repl_hash, content)
180199

181200
# Fix image links.
182201
content = re.sub(r'\/images\/', 'images/', content)
@@ -221,6 +240,10 @@ def _collect_markdown_files_from_source(
221240
if entry.is_dir() is True:
222241
log.detail(f"Processing directory: {entry}")
223242

243+
title = ' '.join(title_tokens[1:])
244+
245+
markdown_files.append(VTEMarkdownFile("", current_depth, prefix, title))
246+
224247
self._collect_markdown_files_from_source(
225248
entry,
226249
(current_depth + 1),

0 commit comments

Comments
 (0)