diff options
author | Gustav Wikström <gustav@whil.se> | 2020-01-14 02:52:12 +0100 |
---|---|---|
committer | Gustav Wikström <gustav@whil.se> | 2020-01-14 04:07:55 +0100 |
commit | 32aa7139fd62af390784957761da78729a0cc658 (patch) | |
tree | ac5f4c130bbb9521ae9df3f3aac22bf734018837 | |
parent | c1aed9f809ea89ee2df79f966327aab558c0ad69 (diff) | |
download | org-mode-32aa7139fd62af390784957761da78729a0cc658.tar.gz |
Markdown exporter: restructure org-md-link
* lisp/ox-md.el (org-md-link): Restructure slightly to match the code
structure of other exporters. For easier later refactor.
-rw-r--r-- | lisp/ox-md.el | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/lisp/ox-md.el b/lisp/ox-md.el index 91d5c0b..d935ebe 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -385,20 +385,28 @@ channel." ;;;; Link -(defun org-md-link (link contents info) +(defun org-md-link (link desc info) "Transcode LINE-BREAK object into Markdown format. -CONTENTS is the link's description. INFO is a plist used as -a communication channel." - (let ((link-org-files-as-md - (lambda (raw-path) - ;; Treat links to `file.org' as links to `file.md'. - (if (string= ".org" (downcase (file-name-extension raw-path "."))) - (concat (file-name-sans-extension raw-path) ".md") - raw-path))) - (type (org-element-property :type link))) +DESC is the description part of the link, or the empty string. +INFO is a plist holding contextual information. See +`org-export-data'." + (let* ((link-org-files-as-md + (lambda (raw-path) + ;; Treat links to `file.org' as links to `file.md'. + (if (string= ".org" (downcase (file-name-extension raw-path "."))) + (concat (file-name-sans-extension raw-path) ".md") + raw-path))) + (type (org-element-property :type link)) + (raw-path (raw-path (org-element-property :path link))) + (path (cond + ((member type '("http" "https" "ftp" "mailto")) + (concat type ":" path)) + ((string= type "file") + (org-export-file-uri (funcall link-org-files-as-md raw-path))) + (t raw-path)))) (cond ;; Link type is handled by a special function. - ((org-export-custom-protocol-maybe link contents 'md)) + ((org-export-custom-protocol-maybe link desc 'md)) ((member type '("custom-id" "id" "fuzzy")) (let ((destination (if (string= type "fuzzy") (org-export-resolve-fuzzy-link link info) @@ -406,13 +414,13 @@ a communication channel." (pcase (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)))) + (if (not desc) (format "<%s>" path) + (format "[%s](%s)" desc path)))) (`headline (format "[%s](#%s)" ;; Description. - (cond ((org-string-nw-p contents)) + (cond ((org-string-nw-p desc)) ((org-export-numbered-headline-p destination info) (mapconcat #'number-to-string (org-export-get-headline-number destination info) @@ -435,10 +443,9 @@ a communication channel." 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))) - (cond ((not (equal "file" type)) (concat type ":" raw-path)) - ((not (file-name-absolute-p raw-path)) raw-path) - (t (expand-file-name raw-path))))) + (let ((path (cond ((not (equal "file" type)) (concat type ":" raw-path)) + ((not (file-name-absolute-p raw-path)) raw-path) + (t (expand-file-name raw-path)))) (caption (org-export-data (org-export-get-caption (org-export-get-parent-element link)) info))) @@ -446,20 +453,11 @@ a communication channel." (if (not (org-string-nw-p caption)) path (format "%s \"%s\"" path caption))))) ((string= type "coderef") - (let ((ref (org-element-property :path link))) - (format (org-export-get-coderef-format ref contents) - (org-export-resolve-coderef ref info)))) - ((equal type "radio") contents) - (t (let* ((raw-path (org-element-property :path link)) - (path - (cond - ((member type '("http" "https" "ftp" "mailto")) - (concat type ":" raw-path)) - ((string= type "file") - (org-export-file-uri (funcall link-org-files-as-md raw-path))) - (t raw-path)))) - (if (not contents) (format "<%s>" path) - (format "[%s](%s)" contents path))))))) + (format (org-export-get-coderef-format path desc) + (org-export-resolve-coderef path info))) + ((equal type "radio") desc) + (t (if (not desc) (format "<%s>" path) + (format "[%s](%s)" desc path)))))) ;;;; Node Property |