Function: gptel-markdown--validate-link

gptel-markdown--validate-link is a byte-compiled function defined in gptel-request.el.

Signature

(gptel-markdown--validate-link LINK)

Documentation

Validate a Markdown LINK as sendable under the current gptel settings.

Return a form (validp link-type path . REST), where REST is a list explaining why sending the link is not supported by gptel. Only the first nil value in REST is guaranteed to be correct.

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(defsubst gptel-markdown--validate-link (link)
  "Validate a Markdown LINK as sendable under the current gptel settings.

Return a form (validp link-type path . REST), where REST is a list
explaining why sending the link is not supported by gptel.  Only the
first nil value in REST is guaranteed to be correct."
  (let ((mime))
    (if-let* ((path (nth 3 link))
              (prefix (or (string-search "://" path) 0))
              (link-type (if (= prefix 0) "file" (substring path 0 prefix)))
              (path (if (and (equal link-type "file") (> prefix 0))
                        (substring path (+ prefix 3)) path))
              (resource-type
               (or (and (equal link-type "file") 'file)
                   (and (gptel--model-capable-p 'url)
                        (member link-type '("http" "https" "ftp")) 'url)))
              (user-check (funcall gptel-markdown-validate-link link))
              (readablep (or (eq resource-type 'url) ;Assume URLs are reachable
                             (file-remote-p default-directory)
                             (file-remote-p path)
                             (file-readable-p path)))
              (mime-valid
               (if (or (eq resource-type 'url)
                       (with-memoization
                           (alist-get (expand-file-name path)
                                      gptel--link-type-cache
                                      nil nil #'string=)
                         (gptel--file-binary-p path)))
                   (progn (setq mime (mailcap-file-name-to-mime-type path))
                          (gptel--model-mime-capable-p mime))
                 t)))
        (list t link-type path resource-type user-check readablep mime-valid mime)
      (list nil link-type path resource-type user-check readablep mime-valid mime))))