Browse Source

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<a id="sec-2"></a>

  Consider this list:

  -   three
  -   four

Thanks to Rafael for reporting it.
http://permalink.gmane.org/gmane.emacs.orgmode/89840
Nicolas Goaziou 10 years ago
parent
commit
3fed03941a
1 changed files with 19 additions and 12 deletions
  1. 19 12
      lisp/ox-md.el

+ 19 - 12
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)