Skip to content

Commit

Permalink
Add "appendix" datatype to appx* files
Browse files Browse the repository at this point in the history
This commit adds a test and code to automatically apply the "appendix"
datatype to files beginning with "appx", e.g., "appxa", "appx_b", etc.
  • Loading branch information
delfanbaum committed Dec 22, 2022
1 parent fb91cf1 commit 35465f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jupyter_book_to_htmlbook/file_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def process_chapter_single_file(toc_element):
chapter['data-type'] = ch_stub.lower() # type: ignore
else:
chapter['data-type'] = "afterword" # type: ignore
elif ch_stub.lower()[:4] == "appx":
chapter['data-type'] = "appendix"
else:
chapter['data-type'] = 'chapter' # type: ignore
del chapter['class'] # type: ignore
Expand Down
18 changes: 18 additions & 0 deletions tests/test_file_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,21 @@ def test_process_chapter_guessing_datatypes_inferred(
with open(test_out / f'{datatype[0]}.html') as f:
text = f.read()
assert text.find(f'data-type="{datatype[1]}') > -1

def test_process_chapter_appendix_datatypes(self, tmp_path):
"""
Filenames that begin with "appx*" should have the "appendix"
data-type applied.
"""
test_env = tmp_path / 'tmp'
test_out = test_env / 'build'
test_env.mkdir()
test_out.mkdir()
test_file_path = test_env / 'appx_a.html'
shutil.copy('tests/example_book/_build/html/intro.html',
test_file_path)
process_chapter(test_file_path, test_env, test_out)
# the resulting section should have a data-type of "datatype"
with open(test_out / 'appx_a.html') as f:
text = f.read()
assert text.find('data-type="appendix"') > -1

0 comments on commit 35465f6

Please sign in to comment.