Function: shr-parse-base

shr-parse-base is a byte-compiled function defined in shr.el.gz.

Signature

(shr-parse-base URL)

Source Code

;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
(defun shr-parse-base (url)
  ;; Always chop off anchors.
  (when (string-match "#.*" url)
    (setq url (substring url 0 (match-beginning 0))))
  ;; NB: <base href=""> URI may itself be relative to the document's URI.
  (setq url (shr-expand-url url))
  (let* ((parsed (url-generic-parse-url url))
	 (local (or (url-filename parsed) "")))
    (setf (url-filename parsed) "")
    ;; Chop off the bit after the last slash.
    (when (string-match "\\`\\(.*/\\)[^/]+\\'" local)
      (setq local (match-string 1 local)))
    ;; Always make the local bit end with a slash.
    (when (and (not (zerop (length local)))
	       (not (eq (aref local (1- (length local))) ?/)))
      (setq local (concat local "/")))
    (list (url-recreate-url parsed)
	  local
	  (url-type parsed)
	  url)))