org-element: Fix item interpreter when item doesn't start with a paragraph

* contrib/lisp/org-element.el (org-element-item-interpreter): Fix item
  interpreter when item doesn't start with a paragraph.
* testing/lisp/test-org-element.el: Add test.
This commit is contained in:
Nicolas Goaziou 2012-06-12 14:29:53 +02:00
parent eb69035d5e
commit f2bfa3a6b2
2 changed files with 33 additions and 23 deletions

View File

@ -684,7 +684,10 @@ CONTENTS is the contents of the element."
(tag (let ((tag (org-element-property :tag item)))
(and tag (org-element-interpret-data tag))))
;; Compute indentation.
(ind (make-string (length bullet) 32)))
(ind (make-string (length bullet) 32))
(item-starts-with-par-p
(eq (org-element-type (car (org-element-contents item)))
'paragraph)))
;; Indent contents.
(concat
bullet
@ -694,8 +697,10 @@ CONTENTS is the contents of the element."
((eq checkbox 'off) "[ ] ")
((eq checkbox 'trans) "[-] "))
(and tag (format "%s :: " tag))
(org-trim
(replace-regexp-in-string "\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))))
(let ((contents (replace-regexp-in-string
"\\(^\\)[ \t]*\\S-" ind contents nil nil 1)))
(if item-starts-with-par-p (org-trim contents)
(concat "\n" contents))))))
;;;; Plain List

View File

@ -1551,26 +1551,31 @@ Outside list"
(ert-deftest test-org-element/plain-list-interpreter ()
"Test plain-list and item interpreters."
;; 1. Unordered list.
(should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
;; 2. Description list.
(should
(equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
;; 3. Ordered list.
(should
(equal (let ((org-plain-list-ordered-item-terminator t))
(org-test-parse-and-interpret "1. Item"))
"1. Item\n"))
;; 4. Ordered list with counter.
(should
(equal (let ((org-plain-list-ordered-item-terminator t))
(org-test-parse-and-interpret "1. [@5] Item"))
"5. [@5] Item\n"))
;; 5. List with check-boxes.
(should
(equal (org-test-parse-and-interpret
"- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
"- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n")))
(let ((org-list-two-spaces-after-bullet-regexp nil))
;; 1. Unordered list.
(should (equal (org-test-parse-and-interpret "- item 1") "- item 1\n"))
;; 2. Description list.
(should
(equal (org-test-parse-and-interpret "- tag :: desc") "- tag :: desc\n"))
;; 3. Ordered list.
(should
(equal (let ((org-plain-list-ordered-item-terminator t))
(org-test-parse-and-interpret "1. Item"))
"1. Item\n"))
;; 4. Ordered list with counter.
(should
(equal (let ((org-plain-list-ordered-item-terminator t))
(org-test-parse-and-interpret "1. [@5] Item"))
"5. [@5] Item\n"))
;; 5. List with check-boxes.
(should
(equal (org-test-parse-and-interpret
"- [-] Item 1\n - [X] Item 2\n - [ ] Item 3")
"- [-] Item 1\n - [X] Item 2\n - [ ] Item 3\n"))
;; 6. Item not starting with a paragraph.
(should
(equal (org-test-parse-and-interpret "-\n | a | b |")
"- \n | a | b |\n"))))
(ert-deftest test-org-element/quote-block-interpreter ()
"Test quote block interpreter."