ox-md: Allow custom link type export function

* lisp/ox-md.el (org-md-link): Allow custom link type export function.

`md' back-end is now on par with other core export back-ends.

Thanks to Ken Markoff for reponting it.
http://permalink.gmane.org/gmane.emacs.orgmode/90011
This commit is contained in:
Nicolas Goaziou 2014-08-21 11:05:45 +02:00
parent 50da53de51
commit b8b34eadb4

View file

@ -294,57 +294,62 @@ a communication channel."
(concat (file-name-sans-extension raw-path) ".md") (concat (file-name-sans-extension raw-path) ".md")
raw-path)))) raw-path))))
(type (org-element-property :type link))) (type (org-element-property :type link)))
(cond ((member type '("custom-id" "id")) (cond
(let ((destination (org-export-resolve-id-link link info))) ((member type '("custom-id" "id"))
(if (stringp destination) ; External file. (let ((destination (org-export-resolve-id-link link info)))
(let ((path (funcall link-org-files-as-md destination))) (if (stringp destination) ; External file.
(if (not contents) (format "<%s>" path) (let ((path (funcall link-org-files-as-md destination)))
(format "[%s](%s)" contents path))) (if (not contents) (format "<%s>" path)
(concat (format "[%s](%s)" contents path)))
(and contents (concat contents " ")) (concat
(format "(%s)" (and contents (concat contents " "))
(format (org-export-translate "See section %s" :html info) (format "(%s)"
(mapconcat 'number-to-string (format (org-export-translate "See section %s" :html info)
(org-export-get-headline-number (mapconcat 'number-to-string
destination info) (org-export-get-headline-number
"."))))))) destination info)
((org-export-inline-image-p link org-html-inline-image-rules) ".")))))))
(let ((path (let ((raw-path (org-element-property :path link))) ((org-export-inline-image-p link org-html-inline-image-rules)
(if (not (file-name-absolute-p raw-path)) raw-path (let ((path (let ((raw-path (org-element-property :path link)))
(expand-file-name raw-path)))) (if (not (file-name-absolute-p raw-path)) raw-path
(caption (org-export-data (expand-file-name raw-path))))
(org-export-get-caption (caption (org-export-data
(org-export-get-parent-element link)) info))) (org-export-get-caption
(format "![img](%s)" (org-export-get-parent-element link)) info)))
(if (not (org-string-nw-p caption)) path (format "![img](%s)"
(format "%s \"%s\"" path caption))))) (if (not (org-string-nw-p caption)) path
((string= type "coderef") (format "%s \"%s\"" path caption)))))
(let ((ref (org-element-property :path link))) ((string= type "coderef")
(format (org-export-get-coderef-format ref contents) (let ((ref (org-element-property :path link)))
(org-export-resolve-coderef ref info)))) (format (org-export-get-coderef-format ref contents)
((equal type "radio") contents) (org-export-resolve-coderef ref info))))
((equal type "fuzzy") ((equal type "radio") contents)
(let ((destination (org-export-resolve-fuzzy-link link info))) ((equal type "fuzzy")
(if (org-string-nw-p contents) contents (let ((destination (org-export-resolve-fuzzy-link link info)))
(when destination (if (org-string-nw-p contents) contents
(let ((number (org-export-get-ordinal destination info))) (when destination
(when number (let ((number (org-export-get-ordinal destination info)))
(if (atom number) (number-to-string number) (when number
(mapconcat 'number-to-string number ".")))))))) (if (atom number) (number-to-string number)
(t (let* ((raw-path (org-element-property :path link)) (mapconcat 'number-to-string number "."))))))))
(path ;; Link type is handled by a special function.
(cond ((let ((protocol (nth 2 (assoc type org-link-protocols))))
((member type '("http" "https" "ftp")) (and (functionp protocol)
(concat type ":" raw-path)) (funcall protocol (org-link-unescape path) desc 'md))))
((string= type "file") (t (let* ((raw-path (org-element-property :path link))
(let ((path (funcall link-org-files-as-md raw-path))) (path
(if (not (file-name-absolute-p path)) path (cond
;; If file path is absolute, prepend it ((member type '("http" "https" "ftp"))
;; with "file:" component. (concat type ":" raw-path))
(concat "file:" path)))) ((string= type "file")
(t raw-path)))) (let ((path (funcall link-org-files-as-md raw-path)))
(if (not contents) (format "<%s>" path) (if (not (file-name-absolute-p path)) path
(format "[%s](%s)" contents path))))))) ;; If file path is absolute, prepend it
;; with "file:" component.
(concat "file:" path))))
(t raw-path))))
(if (not contents) (format "<%s>" path)
(format "[%s](%s)" contents path)))))))
;;;; Paragraph ;;;; Paragraph