Skip to content

Commit 7077518

Browse files
authored
Merge pull request #34 from oreillymedia/TOOLSREQ-8242-version-bump-and-cleanup
Toolsreq 8242 version bump and cleanup
2 parents b7640c5 + 5944762 commit 7077518

14 files changed

+732
-487
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ Options:
7272

7373
## Release Notes
7474

75+
### 1.0.7
76+
77+
Features:
78+
- Add support for formal code examples in Python and R via the "example" cell tag
79+
- Add support for glossaries
80+
- Add basic support for bibtex bibliographies
81+
82+
Bug fixes:
83+
- Fix bug with top-level heading IDs causing xrefs to fail
84+
- Remove extraneous spacing in figure captions
85+
7586
### 1.0.6
7687
- Add support for sidebars as described in the [Jupyter Book documentation](https://jupyterbook.org/en/stable/content/layout.html#sidebars-within-content)
7788

jupyter_book_to_htmlbook/code_processing.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def process_code(chapter, skip_numbering=False):
1414

1515
for div in highlight_divs:
1616
try:
17-
parent_classes = str(div.parent["class"])
17+
parent_classes = str(div.parent.get("class"))
1818

1919
# apply `data-type` attribute
2020
pre_tag = div.pre
@@ -57,9 +57,6 @@ def process_code(chapter, skip_numbering=False):
5757
except TypeError:
5858
logging.warning(f"Unable to apply cell numbering to {div}")
5959

60-
except KeyError:
61-
logging.warning(f"Unable to apply cell numbering to {div}")
62-
6360
return chapter
6461

6562

@@ -75,14 +72,14 @@ def number_codeblock(pre_block, cell_number):
7572
# grandparent of highlight div contains in/out information
7673
grandparent = pre_block.parent.parent.parent
7774

78-
if "cell_input" in str(grandparent["class"]):
75+
if "cell_input" in str(grandparent.get("class")):
7976
in_block = True
8077
cell_number += 1
8178
marker = f"In [{cell_number}]: "
8279
elif (
83-
"cell_output" in grandparent["class"] and
80+
"cell_output" in grandparent.get("class") and
8481
# ensure we're not in a hidden-input cell
85-
"tag_hide-input" not in grandparent.parent["class"]
82+
"tag_hide-input" not in grandparent.parent.get("class")
8683
):
8784
in_block = False
8885
marker = f"Out[{cell_number}]: "
@@ -141,7 +138,7 @@ def process_code_examples(chapter):
141138
logging.warning(
142139
"Missing first two line comments for uuid and title." +
143140
f"Unable to apply example formatting to {example_cell}.")
144-
return example_cell
141+
return chapter
145142

146143
# ensure comments are within the first three spans (since we
147144
# expect an empty span to start based on their highlighter)

jupyter_book_to_htmlbook/figure_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from bs4 import NavigableString
2+
from bs4 import NavigableString # type: ignore
33

44

55
def process_figures(chapter, build_dir: Path):

jupyter_book_to_htmlbook/file_processing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,14 @@ def process_chapter(toc_element,
225225
"""
226226

227227
chapter, ch_name = process_chapter_soup(toc_element)
228+
logging.info(f"Processing {ch_name}...")
228229

229230
if not chapter: # guard against malformed files
230-
return
231-
232-
logging.info(f"Processing {ch_name}...")
231+
logging.warning(f"Failed to process {toc_element}.")
232+
raise RuntimeError(
233+
f"Failed to process {toc_element}. Please check for error in " +
234+
"your source file(s). Contact the Tools team for additional " +
235+
"support.")
233236

234237
# perform cleans and processing
235238
chapter = clean_chapter(chapter)
@@ -248,7 +251,7 @@ def process_chapter(toc_element,
248251
chapter = process_sidebars(chapter)
249252
chapter = process_subsections(chapter)
250253

251-
if chapter["data-type"] == "glossary":
254+
if chapter.get("data-type") == "glossary":
252255
add_glossary_datatypes(chapter)
253256

254257
chapter, ids = process_ids(chapter, book_ids)

jupyter_book_to_htmlbook/footnote_processing.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ def process_footnotes(chapter):
1010
# move the contents of the ref to the anchor point
1111
for ref in footnote_refs:
1212
try:
13-
ref_id = ref['href'].split('#')[-1]
13+
ref_id = ref.get('href').split('#')[-1]
1414
# double next_sibling b/c next sibling is a space
1515
ref_location = chapter.find(
1616
"dt", {"id": ref_id}
1717
).next_sibling.next_sibling
1818
footnote_contents = ref_location.find('p').children
1919
ref.name = 'span'
2020
ref['data-type'] = 'footnote'
21-
del(ref['href'])
22-
del(ref['class'])
23-
del(ref['id'])
21+
del ref['href']
22+
del ref['class']
23+
del ref['id']
2424
ref.string = ''
2525
for child in footnote_contents:
2626
ref.append(child)
27-
except KeyError:
28-
logging.warning(f'Error converting footnote "{ref}".')
27+
2928
except AttributeError:
3029
logging.warning(f'Error converting footnote "{ref}".')
3130
# remove the list of footnote contents

jupyter_book_to_htmlbook/reference_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def process_interal_refs(chapter):
3434
parent.contents = ref
3535
# remove any id tags on the parent to avoid duplicates
3636
del parent['id']
37-
elif ref['href'].find('htt') > -1:
37+
elif ref.get('href').find('htt') > -1:
3838
logging.warning(f"External image reference: {ref['href']}")
3939
else: # i.e., non reference xrefs
4040
ref['data-type'] = 'xref'

jupyter_book_to_htmlbook/text_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def move_span_ids_to_sections(chapter):
5252
span.next_sibling.name in ["h1", "h2", "h3", "h4", "h5"]
5353
):
5454
# add span id to section
55-
span.parent['id'] = span['id']
55+
span.parent['id'] = span.get('id')
5656
# remove the now unneeded span
5757
span.decompose()
5858
return chapter

jupyter_book_to_htmlbook/toc_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_book_toc(src_dir: Path) -> list:
4444
toc = load(f.read(), SafeLoader)
4545
# exit if we see some format other than jb-book
4646
try:
47-
if toc["format"] != "jb-book":
47+
if toc.get("format") != "jb-book":
4848
message = ("Unsupported jupyter book format: " +
4949
toc["format"] + ". The only supported" +
5050
" format is 'jb-book'.")

0 commit comments

Comments
 (0)