Skip to content

Commit c70efa1

Browse files
committed
Bug fix: part IDs now refer to the correct part
Also, a little further cleanup in test_file_processing that I noticed while looking for the parts tests
1 parent f6187f0 commit c70efa1

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

jupyter_book_to_htmlbook/file_processing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ def process_part(part_path: Path, output_dir: Path):
3737
part_number = info.group(1)
3838
# undo earlier space replacement and do a simple title case
3939
part_name = info.group(2).replace('-', ' ')
40+
# just to make the string fit better
41+
ns = "http://www.w3.org/1999/xhtml"
4042

4143
with open(output_dir / f'part-{part_number}.html', 'wt') as f:
4244
f.write(f"""
43-
<div xmlns="http://www.w3.org/1999/xhtml" data-type="part" id="part-1">
45+
<div xmlns="{ns}" data-type="part" id="part-{part_number}">
4446
<h1>{part_name}</h1>
4547
</div>""".lstrip())
4648
return f'part-{part_number}.html'

tests/test_file_processing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_compile_chapter_parts_happy_path(self, tmp_book_path):
2929
number_of_sections_expected = 2 # the first html file doesn't get one
3030
assert number_of_sections == number_of_sections_expected
3131

32-
def test_process_chapter_single_chapter_file(self, tmp_book_path, capsys):
32+
def test_process_chapter_single_chapter_file(self, tmp_book_path):
3333
"""
3434
happy path for chapter processing a single chapter file
3535
@@ -161,7 +161,7 @@ def test_process_chapter_with_subfiles(self, tmp_book_path):
161161
assert "ch02" in result
162162
assert os.path.exists(test_out / 'ch02.00.html')
163163

164-
def test_process_chapter_with_subsections(self, tmp_book_path, capsys):
164+
def test_process_chapter_with_subsections(self, tmp_book_path):
165165
"""
166166
ensure subsections are getting data-typed appropriately
167167
"""
@@ -315,7 +315,7 @@ def test_process_chapter_appendix_datatypes(self, tmp_path):
315315
text = f.read()
316316
assert text.find('data-type="appendix"') > -1
317317

318-
def test_process_appendix_with_subsections(self, tmp_path, capsys):
318+
def test_process_appendix_with_subsections(self, tmp_path):
319319
"""
320320
ensure subsections are getting data-typed appropriately when
321321
they're a part of an appendix

tests/test_part_processing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ def test_process_part_bad_name(self, tmp_path, caplog):
2626
result = process_part(part_path, tmp_path)
2727
assert result is None
2828
assert "unable to parse part information" in caplog.text.lower()
29+
30+
def test_process_part_id_is_correct(self, tmp_path):
31+
"""
32+
Sanity check test to confirm that a prior bug isn't (re)introduced
33+
"""
34+
part_path = Path(tmp_path / '_jb_part-20-Part.html')
35+
result = process_part(part_path, tmp_path)
36+
assert result == 'part-20.html'
37+
with open(tmp_path / 'part-20.html') as f:
38+
text = f.read()
39+
assert text.find('id="part-20"') > 0

0 commit comments

Comments
 (0)