Skip to content

Commit f6187f0

Browse files
committed
Remove table caption number
Since atlas automatically adds these, we should ensure they're removing during processing. This commit also contains some other misc. cleanup and the explicit addition of a table into our "example book."
1 parent 5b77721 commit f6187f0

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

jupyter_book_to_htmlbook/text_processing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
def clean_chapter(chapter, rm_numbering=True):
22
"""
33
"Cleans" the chapter from any script or style tags, removes table borders,
4-
table valign/width attributes, removes any style attrs, and by default
5-
removes any section numbering.
4+
table valign/width attributes, caption numbering, removes any style attrs,
5+
and by default removes any section numbering.
66
"""
77
remove_tags = ['style', 'script']
88
remove_attrs = ['style', 'valign', 'halign', 'width']
@@ -13,6 +13,8 @@ def clean_chapter(chapter, rm_numbering=True):
1313
tag.decompose()
1414
if tag.name == 'table':
1515
del tag['border']
16+
if tag.find("span", class_="caption-number"):
17+
tag.find("span", class_="caption-number").decompose()
1618

1719
for attr in remove_attrs:
1820
for tag in chapter.find_all(attrs={attr: True}):

tests/example_book/_build/html/notebooks/markup.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,27 @@ <h1>Some Title</h1>
350350
</div></li>
351351
<li><p>This is a second bullet point, with some <em>formatting</em> which must, remember, be done in HTML as a part of the passthrough.</p></li>
352352
</ul>
353+
<p>Also did we mention tables? Tables. Borrowed from the example docs, see <a class="reference internal" href="#example-table"><span class="std std-numref">Table 1</span></a></p>
354+
<table class="table" id="example-table">
355+
<caption><span class="caption-number">Table 1 </span><span class="caption-text">Table title</span><a class="headerlink" href="#example-table" title="Permalink to this table">#</a></caption>
356+
<colgroup>
357+
<col style="width: 50%" />
358+
<col style="width: 50%" />
359+
</colgroup>
360+
<thead>
361+
<tr class="row-odd"><th class="head"><p>Col1</p></th>
362+
<th class="head"><p>Col2</p></th>
363+
</tr>
364+
</thead>
365+
<tbody>
366+
<tr class="row-even"><td><p>Row1 under Col1</p></td>
367+
<td><p>Row1 under Col2</p></td>
368+
</tr>
369+
<tr class="row-odd"><td><p>Row2 under Col1</p></td>
370+
<td><p>Row2 under Col2</p></td>
371+
</tr>
372+
</tbody>
373+
</table>
353374
<p>Of course, sometimes a pagebreak is needed. If it’s a paragraph, you can do something like the following:</p>
354375
<div class="highlight-html notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">p</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;pagebreak-before&quot;</span><span class="p">&gt;</span>
355376
Just like in a regular HTML book!

0 commit comments

Comments
 (0)