Skip to content

Commit 1b7e7d6

Browse files
authored
Merge pull request #41 from oreillymedia/bug-fix-rm-spans-pre-class
Bug fix for platform surprise class styling
2 parents ad32732 + 0e88a74 commit 1b7e7d6

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

README.md

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

7373
## Release Notes
7474

75+
### 1.0.9
76+
77+
Bug fixes:
78+
- Remove spans inside `<code>` tags that display incorrectly on the ORM learning platform.
79+
7580
### 1.0.8
7681

7782
Bug fixes:

jupyter_book_to_htmlbook/code_processing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ def process_code(chapter, skip_numbering=False):
6060
return chapter
6161

6262

63+
def process_inline_code(chapter):
64+
"""
65+
Because the platform occasionally has unexpected class styling, we want to
66+
make sure that inline code in particular is clean. Note that the current
67+
target version of Jupyter Book doesn't put <code> inside <pre> tags, so our
68+
"dumb" inline searcher should work. There is a test to confirm this.
69+
70+
NOTE: This is a temporary fix; we should really clean out all classes
71+
except those we explicitly want from the chapter files
72+
"""
73+
inline_codes = chapter.find_all("code")
74+
75+
for code in inline_codes:
76+
if code.find("span"):
77+
code.span.unwrap()
78+
79+
return chapter
80+
81+
6382
def number_codeblock(pre_block, cell_number):
6483
"""
6584
Adds numbering markers (`In [##]: ` or `Out[##]: `) to cell blocks

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "jupyter-book-to-htmlbook"
3-
version = "1.0.8"
3+
version = "1.0.9"
44
description = "A script to convert jupyter book html files to htmlbook for consumption in Atlas"
55
authors = ["delfanbaum"]
66

tests/test_code_processing.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from bs4 import BeautifulSoup # type: ignore
66
from jupyter_book_to_htmlbook.code_processing import (
77
process_code,
8+
process_inline_code,
89
number_codeblock,
910
process_code_examples
1011
)
@@ -557,3 +558,29 @@ def test_examples_malformed_r(self, caplog):
557558
assert not example_div.find("h5", string="A formal R example")
558559
assert result == malformed_example
559560
assert "Missing first two line comments for" in log
561+
562+
563+
class TestInlineCode:
564+
"""
565+
Smoke tests around the translation of inline code
566+
"""
567+
568+
def test_unwrap_inline_spans(self):
569+
"""
570+
We should not allow spans inside inline code
571+
"""
572+
573+
html = BeautifulSoup("""<p>Some text with
574+
<code><span class="pre">code</span></code>.</p>""",
575+
"html.parser")
576+
result = process_inline_code(html)
577+
578+
assert not result.find("span")
579+
assert str(result.find("code")) == "<code>code</code>"
580+
581+
def test_unwrap_inline_spans_does_not_affect_pre(self,
582+
code_example_data_type):
583+
expected = str(code_example_data_type)
584+
result = process_inline_code(code_example_data_type)
585+
assert str(result) == expected
586+

0 commit comments

Comments
 (0)