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 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 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 a filename (instead of a URL) to be visited and
1513+ use its return value instead of the filename in the link. For
1514+ example, if absolute filenames are actually relative to a server
1515+ root directory, you can set
1516+ `markdown-translate-filename-function' to a function that
1517+ prepends the root directory to the given 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 filenames using `markdown-filename-translate-function'."
80898108 (interactive)
80908109 (if (markdown-link-p)
80918110 (let* ((url (markdown-link-url))
@@ -8101,7 +8120,8 @@ 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 (funcall markdown-translate-filename-function file)))))
81058125 (user-error "Point is not at a Markdown link or URL")))
81068126
81078127(defun markdown-fontify-inline-links (last)
0 commit comments