Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions scrapegraphai/utils/convert_to_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
convert_to_md module
"""

from urllib.parse import urlparse

import html2text


Expand All @@ -29,8 +27,6 @@ def convert_to_md(html: str, url: str = None) -> str:
h.body_width = 0

if url is not None:
parsed_url = urlparse(url)
domain = f"{parsed_url.scheme}://{parsed_url.netloc}"
h.baseurl = domain
h.baseurl = url

return h.handle(html)
9 changes: 9 additions & 0 deletions tests/utils/convert_to_md_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ def test_html_with_links_and_images():
assert convert_to_md(html) is not None


def test_relative_links_use_document_url_as_base():
html = '<a href="guide.html">Guide</a><img src="images/logo.png" alt="Logo">'

markdown = convert_to_md(html, "https://example.com/docs/index.html")

assert "[Guide](https://example.com/docs/guide.html)" in markdown
assert "![Logo](https://example.com/docs/images/logo.png)" in markdown


def test_html_with_tables():
html = """
<table>
Expand Down
Loading