Skip to content

Commit

Permalink
Support descriptive lists nested in other lists
Browse files Browse the repository at this point in the history
This is a workaround for Blackfriday limitation, as there doesn't seem
to be a way to nest Blackfriday syntax descriptive/definition lists.
  • Loading branch information
kaushalmodi committed Jan 16, 2018
1 parent cfaea8b commit 972f8b7
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
35 changes: 27 additions & 8 deletions ox-blackfriday.el
Expand Up @@ -461,26 +461,45 @@ contextual information."
(if (org-blackfriday--ordered-list-with-custom-counter-p parent-list)
(org-html-format-list-item contents 'ordered nil info
(org-element-property :counter item))
(let* ((type (org-element-property :type (org-export-get-parent item)))
(let* ((parent-list (org-export-get-parent item))
(parent-list-type (org-element-property :type parent-list))
(desc-list? (eq parent-list-type 'descriptive))
(grandparent (when desc-list?
(org-export-get-parent parent-list)))
(grandparent-type (when desc-list?
(org-element-type grandparent)))
(list-is-nested (eq 'item grandparent-type))
;; Export the descriptive list items like that in
;; ox-md.el if this descriptive list is nested in some
;; other list, because the Blackfriday style descriptive
;; list syntax seems to work only at top level (i.e. not
;; when that list is nested).
(ox-md-style-desc-list (and desc-list? list-is-nested))
(bf-style-desc-list (and desc-list? (not list-is-nested)))
(struct (org-element-property :structure item))
(item-num (car (last (org-list-get-item-number
(org-element-property :begin item)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct)))))
(bullet (cond
((eq type 'unordered)
((or (eq parent-list-type 'unordered)
ox-md-style-desc-list)
"-")
((eq type 'ordered)
((eq parent-list-type 'ordered)
(format "%d." item-num))
(t ;Descriptive
(t ;Non-nested descriptive list item
(when (> item-num 1)
"\n")))) ;Newline between each descriptive list item
(padding (unless (eq type 'descriptive)
(padding (unless bf-style-desc-list
(make-string (- 4 (length bullet)) ? )))
(tag (when (eq type 'descriptive)
(let ((tag1 (org-element-property :tag item)))
(and tag1 (format "%s\n: " (org-export-data tag1 info)))))))
(tag (when desc-list?
(let* ((tag1 (org-element-property :tag item))
(tag1-str (org-export-data tag1 info)))
(when tag1
(if ox-md-style-desc-list
(format "**%s:** " tag1-str)
(format "%s\n: " tag1-str)))))))
(concat bullet
padding
(pcase (org-element-property :checkbox item)
Expand Down
24 changes: 23 additions & 1 deletion test/site/content-org/all-posts.org
Expand Up @@ -2399,7 +2399,7 @@ element than the /bar*/ items.

- bar1 :: description
- bar2 :: description
** Nested lists
** Nested lists :@upstream:
:PROPERTIES:
:EXPORT_FILE_NAME: nested-lists
:EXPORT_DATE: 2017-07-31
Expand All @@ -2414,6 +2414,28 @@ element than the /bar*/ items.
- zoo2
1. numbered1
2. numbered2
*** Unordered list inside descriptive list
- bar1 :: description for bar1
- foo1
- foo2
- bar2 :: description for bar2
- foo3
- foo4
*** Descriptive list inside unordered list
*Seems like Blackfriday style descriptive list syntax does not work
when that list is nested in other lists.*

So in that case, switch back to the descriptive list syntax used in
=ox-md=.

-----

- foo1
- bar1 :: description for bar1
- bar2 :: description for bar2
- foo2
- bar3 :: description for bar3
- bar4 :: description for bar4
** Force ordered list numbering :custom_counter:
:PROPERTIES:
:EXPORT_DATE: 2017-08-01
Expand Down
32 changes: 32 additions & 0 deletions test/site/content/posts/nested-lists.md
Expand Up @@ -2,6 +2,7 @@
title = "Nested lists"
date = 2017-07-31
tags = ["lists"]
categories = ["upstream"]
draft = false
+++

Expand All @@ -15,3 +16,34 @@ draft = false
- zoo2
1. numbered1
2. numbered2


## Unordered list inside descriptive list {#unordered-list-inside-descriptive-list}

bar1
: description for bar1
- foo1
- foo2

bar2
: description for bar2
- foo3
- foo4


## Descriptive list inside unordered list {#descriptive-list-inside-unordered-list}

**Seems like Blackfriday style descriptive list syntax does not work
when that list is nested in other lists.**

So in that case, switch back to the descriptive list syntax used in
`ox-md`.

---

- foo1
- **bar1:** description for bar1
- **bar2:** description for bar2
- foo2
- **bar3:** description for bar3
- **bar4:** description for bar4

0 comments on commit 972f8b7

Please sign in to comment.