Skip to content

Commit

Permalink
nsx: fix duplicated src attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Jan 2, 2025
1 parent 572f41f commit 2f313e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/formats/synology_note_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import difflib
import json
from pathlib import Path
import re
from urllib.parse import urlparse

from bs4 import BeautifulSoup
Expand All @@ -27,10 +26,8 @@ class Attachment:


def streamline_html(content_html: str) -> str:
# hack: In the original data, the attachment_id is stored in the
# "ref" attribute. Mitigate by storing it in the "src" attribute.
content_html = re.sub("<img.*?ref=", "<img src=", content_html)

# TODO
# pylint: disable=too-many-branches
# 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"):
Expand Down Expand Up @@ -74,6 +71,12 @@ def streamline_html(content_html: str) -> str:
iframe.string = iframe.attrs["src"]
iframe.attrs = {"href": iframe.attrs["src"]}

# hack: In the original data, the attachment_id is stored in the
# "ref" attribute. Mitigate by storing it in the "src" attribute.
for img in soup.find_all("img"):
if (new_src := img.attrs.get("ref")) is not None:
img.attrs["src"] = new_src

return str(soup)


Expand Down
2 changes: 2 additions & 0 deletions test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def compare_dirs(dir1: Path, dir2: Path):
[["synology_note_station/test_3/notestation-test-books.nsx"]],
[["synology_note_station/test_4/test.nsx"]],
[["synology_note_station/test_5/20241005_184010_8701_demouser.nsx"]],
# [["synology_note_station/test_6/test8.nsx"]],
# [["synology_note_station/test_7/test10.nsx"]],
[["textbundle/test_1/example.textpack"]],
[["textbundle/test_2/Bug report in tables_bear.textbundle"]],
[["textbundle/test_3/Python CHP NOTES.textbundle"]],
Expand Down

0 comments on commit 2f313e1

Please sign in to comment.