Skip to content

Commit

Permalink
don't fail if there is no table body
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Oct 5, 2024
1 parent 3f18acd commit 95e3269
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/formats/synology_note_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ def streamline_html(content_html: str) -> str:
# another hack: make the first row of a table to the header
soup = BeautifulSoup(content_html, "html.parser")
for table in soup.find_all("table"):
# Remove all divs, since they cause pandoc to fail converting the table.
# https://stackoverflow.com/a/32064299/7410886
for div in table.find_all("div"):
div.unwrap()

for row_index, row in enumerate(table.find_all("tr")):
for td in row.find_all("td"):
# tables seem to be headerless always
# make first row to header
if row_index == 0:
td.name = "th"

# remove "tbody"
body = table.find("tbody")
body.unwrap()
if (body := table.find("tbody")) is not None:
body.unwrap()

return str(soup)

Expand Down
2 changes: 1 addition & 1 deletion test/data
Submodule data updated from 223a8a to 3e4a2d

0 comments on commit 95e3269

Please sign in to comment.