summaryrefslogtreecommitdiff
path: root/lisp/org/ox-md.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/ox-md.el')
-rw-r--r--lisp/org/ox-md.el97
1 files changed, 52 insertions, 45 deletions
diff --git a/lisp/org/ox-md.el b/lisp/org/ox-md.el
index 50982add568..1f841c865fa 100644
--- a/lisp/org/ox-md.el
+++ b/lisp/org/ox-md.el
@@ -77,6 +77,7 @@ This variable can be set to either `atx' or `setext'."
(headline . org-md-headline)
(horizontal-rule . org-md-horizontal-rule)
(inline-src-block . org-md-verbatim)
+ (inner-template . org-md-inner-template)
(italic . org-md-italic)
(item . org-md-item)
(line-break . org-md-line-break)
@@ -96,19 +97,26 @@ This variable can be set to either `atx' or `setext'."
;;; Filters
(defun org-md-separate-elements (tree backend info)
- "Make sure elements are separated by at least one blank line.
+ "Fix blank lines between elements.
TREE is the parse tree being exported. BACKEND is the export
back-end used. INFO is a plist used as a communication channel.
+Make sure there's no blank line before a plain list, unless it is
+located right after a paragraph. Otherwise, add a blank line
+between elements. Blank lines between items are preserved.
+
Assume BACKEND is `md'."
- (org-element-map tree org-element-all-elements
+ (org-element-map tree (remq 'item org-element-all-elements)
(lambda (elem)
- (unless (eq (org-element-type elem) 'org-data)
- (org-element-put-property
- elem :post-blank
- (let ((post-blank (org-element-property :post-blank elem)))
- (if (not post-blank) 1 (max 1 post-blank)))))))
+ (org-element-put-property
+ elem :post-blank
+ (if (and (eq (org-element-type (org-export-get-next-element elem info))
+ 'plain-list)
+ (not (and (eq (org-element-type elem) 'paragraph)
+ (org-export-get-previous-element elem info))))
+ 0
+ 1))))
;; Return updated tree.
tree)
@@ -149,7 +157,7 @@ channel."
(replace-regexp-in-string
"^" " "
(org-remove-indentation
- (org-element-property :value example-block))))
+ (org-export-format-code-default example-block info))))
;;;; Headline
@@ -244,7 +252,8 @@ a communication channel."
(off "[ ] "))
(let ((tag (org-element-property :tag item)))
(and tag (format "**%s:** "(org-export-data tag info))))
- (org-trim (replace-regexp-in-string "^" " " contents)))))
+ (and contents
+ (org-trim (replace-regexp-in-string "^" " " contents))))))
;;;; Line Break
@@ -262,24 +271,18 @@ channel."
"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-html-maybe
+ (let ((link-org-files-as-md
(function
- (lambda (raw-path info)
- ;; Treat links to `file.org' as links to `file.html', if
- ;; needed. See `org-html-link-org-files-as-html'.
- (cond
- ((and org-html-link-org-files-as-html
- (string= ".org"
- (downcase (file-name-extension raw-path "."))))
- (concat (file-name-sans-extension raw-path) "."
- (plist-get info :html-extension)))
- (t raw-path)))))
+ (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)))
(cond ((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-html-maybe
- destination info)))
+ (let ((path (funcall link-org-files-as-md destination)))
(if (not contents) (format "<%s>" path)
(format "[%s](%s)" contents path)))
(concat
@@ -293,19 +296,18 @@ a communication channel."
((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
- (expand-file-name raw-path)))))
- (format "![%s](%s)"
- (let ((caption (org-export-get-caption
- (org-export-get-parent-element link))))
- (when caption (org-export-data caption info)))
- path)))
+ (expand-file-name raw-path))))
+ (caption (org-export-data
+ (org-export-get-caption
+ (org-export-get-parent-element link)) info)))
+ (format "![img](%s)"
+ (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")
- (let ((destination (org-export-resolve-radio-link link info)))
- (org-export-data (org-element-contents destination) info)))
+ ((equal type "radio") contents)
((equal type "fuzzy")
(let ((destination (org-export-resolve-fuzzy-link link info)))
(if (org-string-nw-p contents) contents
@@ -315,20 +317,17 @@ a communication channel."
(if (atom number) (number-to-string number)
(mapconcat 'number-to-string number "."))))))))
(t (let* ((raw-path (org-element-property :path link))
- (path (cond
- ((member type '("http" "https" "ftp"))
- (concat type ":" raw-path))
- ((equal type "file")
- ;; Treat links to ".org" files as ".html",
- ;; if needed.
- (setq raw-path
- (funcall --link-org-files-as-html-maybe
- raw-path info))
- ;; If file path is absolute, prepend it
- ;; with protocol component - "file://".
- (if (not (file-name-absolute-p raw-path)) raw-path
- (concat "file://" (expand-file-name raw-path))))
- (t raw-path))))
+ (path
+ (cond
+ ((member type '("http" "https" "ftp"))
+ (concat type ":" raw-path))
+ ((string= type "file")
+ (let ((path (funcall link-org-files-as-md raw-path)))
+ (if (not (file-name-absolute-p path)) 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)))))))
@@ -403,6 +402,14 @@ a communication channel."
;;;; Template
+(defun org-md-inner-template (contents info)
+ "Return body of document after converting it to Markdown syntax.
+CONTENTS is the transcoded contents string. INFO is a plist
+holding export options."
+ ;; Make sure CONTENTS is separated from table of contents and
+ ;; footnotes with at least a blank line.
+ (org-trim (org-html-inner-template (concat "\n" contents "\n") info)))
+
(defun org-md-template (contents info)
"Return complete document string after Markdown conversion.
CONTENTS is the transcoded contents string. INFO is a plist used