Skip to content

Resolve HTML links and images against the document base URL - #2501

Open
Kunpeng Xie (pentaoa) wants to merge 1 commit into
microsoft:mainfrom
pentaoa:fix/html-relative-links
Open

Kunpeng Xie (pentaoa) wants to merge 1 commit into
microsoft:mainfrom
pentaoa:fix/html-relative-links

Conversation

@pentaoa

Copy link
Copy Markdown

Fixes #2500.

A page at https://example.com/docs/page.html containing <a href="guide.html"> currently produces a relative Markdown link. Its target is lost when the output is used outside the original page. Resolve rendered links and images against the supplied source URL, honoring the first <base href> when present.

The change is confined to HtmlConverter and resolves a[href], img[src], and img[data-src] before Markdown conversion. Existing link filtering and data-URI handling remain in the Markdown converter. Relative URLs stay relative when there is no source/base information; a malformed URL does not discard the document.

Tests cover source and explicit bases, relative bases, first-base precedence, normal/lazy images, encoded paths, absolute links, malformed bases, and MarkItDown.convert_response() using the final response URL. Six of the initial seven regression cases failed before the fix. The final HTML and RSS suites pass 142 tests. Black and git diff --check pass; no dependencies or network access were added. The full multi-format suite was not run.

AI assistance: OpenAI Codex was used for investigation, implementation, and local test execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML conversion loses the base URL for relative links and images

1 participant