Skip to content

Commit

Permalink
fix zoho tables
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Apr 14, 2024
1 parent c2a2593 commit e3f8275
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ If something else is not working, please check the issues first. If you can't fi
[4]

- Export as HTML.
- Checklists and tables are not properly converted.
- Checklists are converted to plain lists. This might change with a newer pandoc version.

## Why Joplin's data API is used?

Expand Down
41 changes: 38 additions & 3 deletions src/apps/zoho_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@
import intermediate_format as imf


def clean_tables(soup):
for table in soup.find_all("table"):
for row in table.find_all("tr"):
for td in row.find_all("td"):
# remove all tags from table data
text_only = td.text
td.clear()
td.append(text_only)
# 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()


def clean_task_lists(soup):
# TODO: Not sure why the cleaned task lists still don't work.
# It works online. Maybe caused by an old pandoc version.
for task_list in soup.find_all("div", class_="checklist"):
task_list.name = "ul"
# remove the spans
for span in task_list.find_all("span"):
span.unwrap()
# remove the first divs
for child in task_list.children:
child.unwrap()
# convert the second divs to list items
for child in task_list.children:
child.name = "li"


class Converter(converter.BaseConverter):

def prepare_input(self, input_: Path) -> Path | None:
Expand Down Expand Up @@ -118,10 +151,12 @@ def convert_note(self, file_: Path):
# - checklists are note working, even with "+task_lists"
# - tables are not working
if soup.body is not None:
note_data["body"] = common.html_text_to_markdown(str(soup.body))
clean_tables(soup)
clean_task_lists(soup)
note_data["body"] = common.html_text_to_markdown(str(soup))

# resources and internal links
resources, note_links = self.parse_links(note_data["body"])
# resources and internal links
resources, note_links = self.parse_links(note_data["body"])

# create note
parent_notebook.child_notes.append(
Expand Down

0 comments on commit e3f8275

Please sign in to comment.