add separator for tables' header
This commit is contained in:
@ -2,42 +2,6 @@
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
html = """
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>56</td>
|
||||
<td>Matt</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>42</td>
|
||||
<td>Colin</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>23</td>
|
||||
<td>Lisa</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>45</td>
|
||||
<td>John</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><table></code></td>
|
||||
<td><code><e></code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><a href="https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png">Sublime Text Logo</a></p>
|
||||
"""
|
||||
|
||||
def python_table(s_table):
|
||||
"""Transform BeautifulSoup table into list of list"""
|
||||
rows = []
|
||||
@ -55,6 +19,11 @@ def pre_table(s_table):
|
||||
cols_width[i] = len(cell.text)
|
||||
text = '<pre class="table"><code>'
|
||||
for i, row in enumerate(rows):
|
||||
if i == 1:
|
||||
for j, cell in enumerate(row):
|
||||
text += '|' + '-' * (cols_width[j] + 2)
|
||||
text += '|\n'
|
||||
|
||||
for j, cell in enumerate(row):
|
||||
text += '| ' + ''.join(str(node) for node in cell.contents) \
|
||||
+ ' ' * (cols_width[j] - len(cell.text) + 1)
|
||||
|
||||
Reference in New Issue
Block a user