summaryrefslogtreecommitdiff
path: root/lisp/ox-md.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ox-md.el')
-rw-r--r--lisp/ox-md.el35
1 files changed, 26 insertions, 9 deletions
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 7842017..2ecafc8 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -1,6 +1,6 @@
;;; ox-md.el --- Markdown Back-End for Org Export Engine
-;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
;; Keywords: org, wp, markdown
@@ -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)
@@ -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
@@ -403,6 +412,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