diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-09-20 22:27:09 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-09-20 22:58:56 +0200 |
commit | a7c8d20ac94916cdcd53001255732e1380697968 (patch) | |
tree | b84347dfa4b50487a613c098d1e25ed7a150aa44 | |
parent | d70a0b62517e71cb62b80ae6227565ffb019f4c1 (diff) | |
download | org-mode-a7c8d20ac94916cdcd53001255732e1380697968.tar.gz |
ox-md: Fix ID and custom ID links export
* lisp/ox-md.el (org-md-link): Use custom ID when referring to
a headline. Also fix default description for custom ID links.
Reported-by: dbitouze@wanadoo.fr (Denis Bitouzé)
<http://permalink.gmane.org/gmane.emacs.orgmode/101344>
-rw-r--r-- | lisp/ox-md.el | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/lisp/ox-md.el b/lisp/ox-md.el index 08358eb..919f296 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -312,23 +312,41 @@ a communication channel." (cond ;; Link type is handled by a special function. ((org-export-custom-protocol-maybe link contents 'md)) - ((member type '("custom-id" "id")) - (let ((destination (org-export-resolve-id-link link info))) - (if (stringp destination) ; External file. - (let ((path (funcall link-org-files-as-md destination))) - (if (not contents) (format "<%s>" path) - (format "[%s](%s)" contents path))) - (concat - (and contents (concat contents " ")) - (format "(%s)" - (format (org-export-translate "See section %s" :html info) - (if (org-export-numbered-headline-p destination info) - (mapconcat #'number-to-string - (org-export-get-headline-number - destination info) - ".") - (org-export-data - (org-element-property :title destination) info)))))))) + ((member type '("custom-id" "id" "fuzzy")) + (let ((destination (if (string= type "fuzzy") + (org-export-resolve-fuzzy-link link info) + (org-export-resolve-id-link link info)))) + (case (org-element-type destination) + (plain-text ; External file. + (let ((path (funcall link-org-files-as-md destination))) + (if (not contents) (format "<%s>" path) + (format "[%s](%s)" contents path)))) + (headline + (format + "[%s](#%s)" + ;; Description. + (cond ((org-string-nw-p contents)) + ((org-export-numbered-headline-p destination info) + (mapconcat #'number-to-string + (org-export-get-headline-number destination info) + ".")) + (t (org-export-data (org-element-property :title destination) + info))) + ;; Reference. + (or (org-element-property :CUSTOM_ID destination) + (org-export-get-reference destination info)))) + (t + (let ((description + (or (org-string-nw-p contents) + (let ((number (org-export-get-ordinal destination info))) + (cond + ((not number) nil) + ((atom number) (number-to-string number)) + (t (mapconcat #'number-to-string number "."))))))) + (when description + (format "[%s](#%s)" + description + (org-export-get-reference destination info)))))))) ((org-export-inline-image-p link org-html-inline-image-rules) (let ((path (let ((raw-path (org-element-property :path link))) (if (not (file-name-absolute-p raw-path)) raw-path @@ -344,21 +362,6 @@ a communication channel." (format (org-export-get-coderef-format ref contents) (org-export-resolve-coderef ref info)))) ((equal type "radio") contents) - ((equal type "fuzzy") - (let* ((destination (org-export-resolve-fuzzy-link link info)) - (description - (or (org-string-nw-p contents) - (let ((number (org-export-get-ordinal destination info))) - (cond - ((not number) - (and (eq 'headline (org-element-type destination)) - (org-export-data - (org-element-property :title destination) info))) - ((atom number) (number-to-string number)) - (t (mapconcat #'number-to-string number "."))))))) - (format "[%s](#%s)" - description - (org-export-get-reference destination info)))) (t (let* ((raw-path (org-element-property :path link)) (path (cond |