Function: markdown-link-at-pos

markdown-link-at-pos is a byte-compiled function defined in markdown-mode.el.

Signature

(markdown-link-at-pos POS)

Documentation

Return properties of link or image at position POS.

Value is a list of elements describing the link:
 0. beginning position
 1. end position
 2. link text
 3. URL
 4. reference label
 5. title text
 6. bang (nil or "!")

Source Code

;; Defined in ~/.emacs.d/elpa/markdown-mode-20260321.143/markdown-mode.el
(defun markdown-link-at-pos (pos)
  "Return properties of link or image at position POS.
Value is a list of elements describing the link:
 0. beginning position
 1. end position
 2. link text
 3. URL
 4. reference label
 5. title text
 6. bang (nil or \"!\")"
  (save-excursion
    (goto-char pos)
    (markdown-backward-to-link-start)
    (let (begin end text url reference title bang)
      (cond
       ;; Inline image or link at point.
       ((thing-at-point-looking-at markdown-regex-link-inline)
        (setq bang (match-string-no-properties 1)
              begin (match-beginning 0)
              text (match-string-no-properties 3)
              url (match-string-no-properties 6))
        ;; consider nested parentheses
        ;; if link target contains parentheses, (match-end 0) isn't correct end position of the link
        (let* ((close-pos (condition-case nil
                              (scan-sexps (match-beginning 5) 1)
                            (error (match-end 0))))
               (destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos)))))
          (setq end close-pos)
          ;; A link can contain spaces if it is wrapped with angle brackets
          (cond ((string-match "\\`<\\(.+\\)>\\'" destination-part)
                 (setq url (match-string-no-properties 1 destination-part)))
                ((string-match "\\([^ ]+\\)\\s-+\\(.+\\)" destination-part)
                 (setq url (match-string-no-properties 1 destination-part)
                       title (substring (match-string-no-properties 2 destination-part) 1 -1)))
                (t (setq url destination-part)))
          (setq url (markdown--unhex-url-string url))))
       ;; Reference link at point.
       ((thing-at-point-looking-at markdown-regex-link-reference)
        (setq bang (match-string-no-properties 1)
              begin (match-beginning 0)
              end (match-end 0)
              text (match-string-no-properties 3))
        (when (char-equal (char-after (match-beginning 5)) ?\[)
          (setq reference (match-string-no-properties 6))))
       ;; Angle bracket URI at point.
       ((thing-at-point-looking-at markdown-regex-angle-uri)
        (setq begin (match-beginning 0)
              end (match-end 0)
              url (match-string-no-properties 2)))
       ;; Plain URI at point.
       ((thing-at-point-looking-at markdown-regex-uri)
        (setq begin (match-beginning 0)
              end (match-end 0)
              url (match-string-no-properties 1))))
      (list begin end text url reference title bang))))