Skip to content

Commit

Permalink
html: several small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Jan 18, 2025
1 parent 40823fd commit 51fc78f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/markdown_lib/html_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@

def div_checklists(soup: BeautifulSoup):
"""Convert div checklists to plain HTML checklists."""
for task_list in soup.find_all("div", class_="checklist"):
# reverse to handle nested lists first
for task_list in reversed(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()
# print(child)
if child.name == "div":
child.unwrap()
# convert the second divs to list items
for child in task_list.children:
child.name = "li"
if child.name == "div":
child.name = "li"


def highlighting(soup: BeautifulSoup):
Expand Down Expand Up @@ -190,5 +194,5 @@ def whitespace_in_math(soup: BeautifulSoup):
LOGGER.debug(f'Unsupported annotation encoding "{encoding}"')
continue
annotation.string = annotation.string.rstrip("\\" + string.whitespace).replace(
"\n\n", "\n\\\\\n"
"\n\n", "\n"
)
2 changes: 1 addition & 1 deletion test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def compare_dirs(dir1: Path, dir2: Path):
[["wordpress/test_4/adversarial-example.xml"]],
[["zettelkasten/test_1/test_zettelkasten.zkn3"]],
[["zim/test_1/notebook"]],
[["zoho_notebook/test_1/Notebook_14Apr2024_1300_html.zip"]],
[["zoho_notebook/test_1/Notebook_18Jan2025_1756_html.zip"]],
],
name_func=name_func,
)
Expand Down

0 comments on commit 51fc78f

Please sign in to comment.