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

View File

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