From 3fed03941aa414e20a919c3f4e9952d70184a2d7 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 16 Aug 2014 16:19:01 +0200 Subject: [PATCH] ox-md: Fix blank lines in output * lisp/ox-md.el (org-md-separate-elements): Outside of lists, preserve blank lines between paragraphs and plain lists. For example Consider this list: - three - four should become # Another test Consider this list: - three - four Thanks to Rafael for reporting it. http://permalink.gmane.org/gmane.emacs.orgmode/89840 --- lisp/ox-md.el | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lisp/ox-md.el b/lisp/ox-md.el index f1c4db986..04439360e 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -102,21 +102,28 @@ This variable can be set to either `atx' or `setext'." 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. +Enforce a blank line between elements. There are three +exceptions to this rule: + + 1. Preserve blank lines between sibling items in a plain list, + + 2. Outside of plain lists, preserve blank lines between + a paragraph and a plain list, + + 3. In an item, remove any blank line before the very first + paragraph and the next sub-list. Assume BACKEND is `md'." (org-element-map tree (remq 'item org-element-all-elements) - (lambda (elem) - (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)))) + (lambda (e) + (cond + ((not (and (eq (org-element-type e) 'paragraph) + (eq (org-element-type (org-export-get-next-element e info)) + 'plain-list))) + (org-element-put-property e :post-blank 1)) + ((not (eq (org-element-type (org-element-property :parent e)) 'item))) + (t (org-element-put-property + e :post-blank (if (org-export-get-previous-element e info) 1 0)))))) ;; Return updated tree. tree) -- 2.11.4.GIT