Skip to content
Open
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
15 changes: 15 additions & 0 deletions crawl4ai/html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ def handle_tag(
if self.tag_callback(self, tag, attrs, start) is True:
return

# Handle <base> tag to update base URL for relative links
if tag == "base" and start:
href = attrs.get("href")
if href:
self.baseurl = href

# first thing inside the anchor tag is another tag
# that produces some output
if (
Expand Down Expand Up @@ -1069,6 +1075,15 @@ def update_params(self, **kwargs):
setattr(self, key, value)

def handle_tag(self, tag, attrs, start):
# Handle <base> tag to update base URL for relative links
# Must be handled before preserved tags since <base> is in <head>
if tag == "base" and start:
href = attrs.get("href") if attrs else None
if href:
self.baseurl = href
# Also let parent class handle it
return super().handle_tag(tag, attrs, start)

# Handle preserved tags
if tag in self.preserve_tags:
if start:
Expand Down