859859;; This is useful for compatibility with `org-mode', which doesn't
860860;; recognize the lowercase variant.
861861;;
862+ ;; * `markdown-translate-filename-function' - A function to be used to
863+ ;; translate absolute filenames in links.
864+ ;;
862865;; Additionally, the faces used for syntax highlighting can be modified to
863866;; your liking by issuing `M-x customize-group RET markdown-faces`
864867;; or by using the "Markdown Faces" link at the bottom of the mode
@@ -1502,6 +1505,21 @@ or from the menu Markdown > Links & Images menu."
15021505 :package-version '(markdown-mode . "2.3"))
15031506(make-variable-buffer-local 'markdown-hide-urls)
15041507
1508+ (defcustom markdown-translate-filename-function #'identity
1509+ "Function to use to translate absolute filenames when following links.
1510+ \\<markdown-mode-map>\\[markdown-follow-thing-at-point] and \\[markdown-follow-link-at-point]
1511+ call this function with the filename as only argument whenever
1512+ they encounter an absolute filename to be visited and use its
1513+ return value instead of the filename in the link. For example, if
1514+ absolute filenames are actually relative to a server root
1515+ directory, you can set `markdown-translate-filename-function' to
1516+ a function that prepends the root directory to the given
1517+ filename."
1518+ :group 'markdown
1519+ :type 'function
1520+ :risky t
1521+ :package-version '(markdown-mode . "2.4"))
1522+
15051523
15061524;;; Regular Expressions =======================================================
15071525
@@ -8085,7 +8103,8 @@ returns nil."
80858103(defun markdown-follow-link-at-point ()
80868104 "Open the current non-wiki link.
80878105If the link is a complete URL, open in browser with `browse-url'.
8088- Otherwise, open with `find-file' after stripping anchor and/or query string."
8106+ Otherwise, open with `find-file' after stripping anchor and/or query string.
8107+ Translate absolute filenames using `markdown-filename-translate-function'."
80898108 (interactive)
80908109 (if (markdown-link-p)
80918110 (let* ((url (markdown-link-url))
@@ -8101,7 +8120,11 @@ Otherwise, open with `find-file' after stripping anchor and/or query string."
81018120 ;; Open full URLs in browser, files in Emacs
81028121 (if full
81038122 (browse-url url)
8104- (when (and file (> (length file) 0)) (find-file file))))
8123+ (when (and file (> (length file) 0))
8124+ (find-file
8125+ (if (file-name-absolute-p file)
8126+ (funcall markdown-translate-filename-function file)
8127+ file)))))
81058128 (user-error "Point is not at a Markdown link or URL")))
81068129
81078130(defun markdown-fontify-inline-links (last)
0 commit comments