aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Brautaset <stig@brautaset.org>2016-02-26 22:26:15 +0000
committerStig Brautaset <stig@brautaset.org>2016-02-26 22:43:13 +0000
commit5cc183c13fcb70efe03bb8600f4295ed423e62b7 (patch)
tree273f55e620616c33339286ab2913c2f43abdc415
parent6fac2785f0f3302eaa430cdc6115f5b8bdc05a59 (diff)
Support nested lists
-rw-r--r--ox-jira.el27
-rw-r--r--ox-jira.org41
-rw-r--r--test/ox-jira-test.el30
-rw-r--r--test/ox-jira-test.org36
4 files changed, 104 insertions, 30 deletions
diff --git a/ox-jira.el b/ox-jira.el
index 628d800..31290de 100644
--- a/ox-jira.el
+++ b/ox-jira.el
@@ -137,20 +137,33 @@ CONTENTS is the text with italic markup. INFO is a plist holding
contextual information."
(format "_%s_" contents))
+(defun org-jira--list-type-path (item)
+ (when (and item (eq 'item (org-element-type item)))
+ (let* ((list (org-element-property :parent item))
+ (list-type (org-element-property :type list)))
+ (cons list-type (org-jira--list-type-path
+ (org-element-property :parent list))))))
+
+(defun org-jira--bullet-string (list-type-path)
+ (apply 'string
+ (mapcar (lambda (x) (if (eq x 'ordered) ?# ?*))
+ list-type-path)))
+
(defun org-jira-item (item contents info)
"Transcode ITEM from Org to JIRA.
CONTENTS is the text with item markup. INFO is a plist holding
contextual information."
- (let* ((parent (org-element-property :parent item))
- (list-type (org-element-property :type parent))
+ (let* ((list-type-path (org-jira--list-type-path item))
+ (bullet-string (org-jira--bullet-string (reverse list-type-path)))
(checkbox (case (org-element-property :checkbox item)
- (on "(/) ")
- (off "(x) ")
- (trans "(i) "))))
+ (on "(/)")
+ (off "(x)")
+ (trans "(i)"))))
(concat
- (if (eq list-type 'ordered) "#" "*")
+ bullet-string
" "
- checkbox
+ (when checkbox
+ (concat checkbox " "))
contents)))
(defun org-jira-link (link desc info)
diff --git a/ox-jira.org b/ox-jira.org
index 3ae8054..e96a283 100644
--- a/ox-jira.org
+++ b/ox-jira.org
@@ -280,24 +280,47 @@
*** Item
- A list item. This could be bullets, or numeric. This can get quite
- complex. We might not handle every case...
+ A list item. The JIRA format for nested lists follows. (You can also
+ mix ordered and unordered lists.)
+
+ : * item
+ : ** sub-item
+ : ** sub-item 2
+ : * item 2
+
+ The item element itself does not know what type it is: that is an
+ attribute of its parent, a plain-list element. We need to walk the path of
+ alternating plain-list and item nodes until there are no more, and extract
+ their type. The type list is used to create a bullet string.
#+BEGIN_SRC emacs-lisp
+ (defun org-jira--list-type-path (item)
+ (when (and item (eq 'item (org-element-type item)))
+ (let* ((list (org-element-property :parent item))
+ (list-type (org-element-property :type list)))
+ (cons list-type (org-jira--list-type-path
+ (org-element-property :parent list))))))
+
+ (defun org-jira--bullet-string (list-type-path)
+ (apply 'string
+ (mapcar (lambda (x) (if (eq x 'ordered) ?# ?*))
+ list-type-path)))
+
(defun org-jira-item (item contents info)
"Transcode ITEM from Org to JIRA.
CONTENTS is the text with item markup. INFO is a plist holding
contextual information."
- (let* ((parent (org-element-property :parent item))
- (list-type (org-element-property :type parent))
+ (let* ((list-type-path (org-jira--list-type-path item))
+ (bullet-string (org-jira--bullet-string (reverse list-type-path)))
(checkbox (case (org-element-property :checkbox item)
- (on "(/) ")
- (off "(x) ")
- (trans "(i) "))))
+ (on "(/)")
+ (off "(x)")
+ (trans "(i)"))))
(concat
- (if (eq list-type 'ordered) "#" "*")
+ bullet-string
" "
- checkbox
+ (when checkbox
+ (concat checkbox " "))
contents)))
#+END_SRC
diff --git a/test/ox-jira-test.el b/test/ox-jira-test.el
index 1ce4c1c..0fe6c5c 100644
--- a/test/ox-jira-test.el
+++ b/test/ox-jira-test.el
@@ -103,6 +103,24 @@ fum" 'jira))))
3. fa
3. fum" 'jira))))
+(ert-deftest ox-jira-test/nested-lists()
+ (should (equal "* fi
+** fo
+*** fa
+**** fum
+" (org-export-string-as "- fi
+ - fo
+ - fa
+ - fum" 'jira)))
+ (should (equal "* fi
+*# fo
+*#* fa
+*#*# fum
+" (org-export-string-as "- fi
+ 1. fo
+ - fa
+ 1. fum" 'jira))))
+
(ert-deftest ox-jira-test/unordered-list-with-checkboxes()
(should (equal "* (x) fi
* (/) fo
@@ -110,12 +128,12 @@ fum" 'jira))))
- [X] fo" 'jira))))
(ert-deftest ox-jira-test/checkboxes-and-statistics()
- (should (equal "h1. Progress \\[50%]
-* (x) fi
-* (/) fo
-" (org-export-string-as "* Progress [50%]
-- [ ] fi
-- [X] fo" 'jira))))
+ (should (equal "* (i) Progress \\[50%]
+** (x) fi
+** (/) fo
+" (org-export-string-as "- [-] Progress [50%]
+ - [ ] fi
+ - [X] fo" 'jira))))
(ert-deftest ox-jira-test/src-blocks ()
(should (equal "{code:none}
diff --git a/test/ox-jira-test.org b/test/ox-jira-test.org
index eb64ac4..8a698f5 100644
--- a/test/ox-jira-test.org
+++ b/test/ox-jira-test.org
@@ -197,6 +197,28 @@
3. fum" 'jira))))
#+END_SRC
+ Ok, we handle flat lists. How about nested ones?
+
+ #+BEGIN_SRC emacs-lisp
+ (ert-deftest ox-jira-test/nested-lists()
+ (should (equal "* fi
+ ,** fo
+ ,*** fa
+ ,**** fum
+ " (org-export-string-as "- fi
+ - fo
+ - fa
+ - fum" 'jira)))
+ (should (equal "* fi
+ ,*# fo
+ ,*#* fa
+ ,*#*# fum
+ " (org-export-string-as "- fi
+ 1. fo
+ - fa
+ 1. fum" 'jira))))
+ #+END_SRC
+
Right! That was simple enough. Let's add some checkboxes.
#+BEGIN_SRC emacs-lisp
@@ -211,16 +233,14 @@
#+BEGIN_SRC emacs-lisp
(ert-deftest ox-jira-test/checkboxes-and-statistics()
- (should (equal "h1. Progress \\[50%]
- ,* (x) fi
- ,* (/) fo
- " (org-export-string-as "* Progress [50%]
- - [ ] fi
- - [X] fo" 'jira))))
+ (should (equal "* (i) Progress \\[50%]
+ ,** (x) fi
+ ,** (/) fo
+ " (org-export-string-as "- [-] Progress [50%]
+ - [ ] fi
+ - [X] fo" 'jira))))
#+END_SRC
-
-
** Source code
I use Org mode for literate programming, and executable lab notes, so we