forked from mirrors/org-mode
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.
This commit is contained in:
parent
c1aed9f809
commit
32aa7139fd
|
@ -385,20 +385,28 @@ channel."
|
||||||
|
|
||||||
;;;; Link
|
;;;; Link
|
||||||
|
|
||||||
(defun org-md-link (link contents info)
|
(defun org-md-link (link desc info)
|
||||||
"Transcode LINE-BREAK object into Markdown format.
|
"Transcode LINE-BREAK object into Markdown format.
|
||||||
CONTENTS is the link's description. INFO is a plist used as
|
DESC is the description part of the link, or the empty string.
|
||||||
a communication channel."
|
INFO is a plist holding contextual information. See
|
||||||
(let ((link-org-files-as-md
|
`org-export-data'."
|
||||||
(lambda (raw-path)
|
(let* ((link-org-files-as-md
|
||||||
;; Treat links to `file.org' as links to `file.md'.
|
(lambda (raw-path)
|
||||||
(if (string= ".org" (downcase (file-name-extension raw-path ".")))
|
;; Treat links to `file.org' as links to `file.md'.
|
||||||
(concat (file-name-sans-extension raw-path) ".md")
|
(if (string= ".org" (downcase (file-name-extension raw-path ".")))
|
||||||
raw-path)))
|
(concat (file-name-sans-extension raw-path) ".md")
|
||||||
(type (org-element-property :type link)))
|
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
|
(cond
|
||||||
;; Link type is handled by a special function.
|
;; 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"))
|
((member type '("custom-id" "id" "fuzzy"))
|
||||||
(let ((destination (if (string= type "fuzzy")
|
(let ((destination (if (string= type "fuzzy")
|
||||||
(org-export-resolve-fuzzy-link link info)
|
(org-export-resolve-fuzzy-link link info)
|
||||||
|
@ -406,13 +414,13 @@ a communication channel."
|
||||||
(pcase (org-element-type destination)
|
(pcase (org-element-type destination)
|
||||||
(`plain-text ; External file.
|
(`plain-text ; External file.
|
||||||
(let ((path (funcall link-org-files-as-md destination)))
|
(let ((path (funcall link-org-files-as-md destination)))
|
||||||
(if (not contents) (format "<%s>" path)
|
(if (not desc) (format "<%s>" path)
|
||||||
(format "[%s](%s)" contents path))))
|
(format "[%s](%s)" desc path))))
|
||||||
(`headline
|
(`headline
|
||||||
(format
|
(format
|
||||||
"[%s](#%s)"
|
"[%s](#%s)"
|
||||||
;; Description.
|
;; Description.
|
||||||
(cond ((org-string-nw-p contents))
|
(cond ((org-string-nw-p desc))
|
||||||
((org-export-numbered-headline-p destination info)
|
((org-export-numbered-headline-p destination info)
|
||||||
(mapconcat #'number-to-string
|
(mapconcat #'number-to-string
|
||||||
(org-export-get-headline-number destination info)
|
(org-export-get-headline-number destination info)
|
||||||
|
@ -435,10 +443,9 @@ a communication channel."
|
||||||
description
|
description
|
||||||
(org-export-get-reference destination info))))))))
|
(org-export-get-reference destination info))))))))
|
||||||
((org-export-inline-image-p link org-html-inline-image-rules)
|
((org-export-inline-image-p link org-html-inline-image-rules)
|
||||||
(let ((path (let ((raw-path (org-element-property :path link)))
|
(let ((path (cond ((not (equal "file" type)) (concat type ":" raw-path))
|
||||||
(cond ((not (equal "file" type)) (concat type ":" raw-path))
|
((not (file-name-absolute-p raw-path)) raw-path)
|
||||||
((not (file-name-absolute-p raw-path)) raw-path)
|
(t (expand-file-name raw-path))))
|
||||||
(t (expand-file-name raw-path)))))
|
|
||||||
(caption (org-export-data
|
(caption (org-export-data
|
||||||
(org-export-get-caption
|
(org-export-get-caption
|
||||||
(org-export-get-parent-element link)) info)))
|
(org-export-get-parent-element link)) info)))
|
||||||
|
@ -446,20 +453,11 @@ a communication channel."
|
||||||
(if (not (org-string-nw-p caption)) path
|
(if (not (org-string-nw-p caption)) path
|
||||||
(format "%s \"%s\"" path caption)))))
|
(format "%s \"%s\"" path caption)))))
|
||||||
((string= type "coderef")
|
((string= type "coderef")
|
||||||
(let ((ref (org-element-property :path link)))
|
(format (org-export-get-coderef-format path desc)
|
||||||
(format (org-export-get-coderef-format ref contents)
|
(org-export-resolve-coderef path info)))
|
||||||
(org-export-resolve-coderef ref info))))
|
((equal type "radio") desc)
|
||||||
((equal type "radio") contents)
|
(t (if (not desc) (format "<%s>" path)
|
||||||
(t (let* ((raw-path (org-element-property :path link))
|
(format "[%s](%s)" desc path))))))
|
||||||
(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)))))))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; Node Property
|
;;;; Node Property
|
||||||
|
|
Loading…
Reference in a new issue