Skip to content

Commit 8829e74

Browse files
authored
Merge pull request #1131 from primorLee/codex/fix-relative-markdown-links
fix: resolve markdown links from the document URL
2 parents 8eee60e + 875385b commit 8829e74

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

scrapegraphai/utils/convert_to_md.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
convert_to_md module
33
"""
44

5-
from urllib.parse import urlparse
6-
75
import html2text
86

97

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

3129
if url is not None:
32-
parsed_url = urlparse(url)
33-
domain = f"{parsed_url.scheme}://{parsed_url.netloc}"
34-
h.baseurl = domain
30+
h.baseurl = url
3531

3632
return h.handle(html)

tests/utils/convert_to_md_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ def test_html_with_links_and_images():
1111
assert convert_to_md(html) is not None
1212

1313

14+
def test_relative_links_use_document_url_as_base():
15+
html = '<a href="guide.html">Guide</a><img src="images/logo.png" alt="Logo">'
16+
17+
markdown = convert_to_md(html, "https://example.com/docs/index.html")
18+
19+
assert "[Guide](https://example.com/docs/guide.html)" in markdown
20+
assert "![Logo](https://example.com/docs/images/logo.png)" in markdown
21+
22+
1423
def test_html_with_tables():
1524
html = """
1625
<table>

0 commit comments

Comments
 (0)