Skip to main content

replace_relative_urls_with_absolute

Function replace_relative_urls_with_absolute 

Source
pub fn replace_relative_urls_with_absolute(
    node: &NodeRef,
    doc_uri: &str,
    base_path: &str,
)
Expand description

Rewrite all relative URLs in <a>, <img>, <picture>, <figure>, <video>, <audio>, and <source> elements under node to absolute URLs using doc_uri and the optional <base href> path.

Special handling for <a> links:

  • javascript: hrefs → the <a> is replaced by a <span> (attributes like id / name are preserved if present).
  • Hash links that point to the element’s own id → same replacement, because the anchor target is preserved as a <span id>.
  • All other hrefs (relative or absolute) → resolved normally.