From 972f8b7208c35be08cbbe475c96bb9cc81ab0b52 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Mon, 15 Jan 2018 23:45:52 -0500 Subject: [PATCH] Support descriptive lists nested in other lists This is a workaround for Blackfriday limitation, as there doesn't seem to be a way to nest Blackfriday syntax descriptive/definition lists. --- ox-blackfriday.el | 35 +++++++++++++++++++------ test/site/content-org/all-posts.org | 24 ++++++++++++++++- test/site/content/posts/nested-lists.md | 32 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/ox-blackfriday.el b/ox-blackfriday.el index 8b5d6dc4..dcff75c6 100644 --- a/ox-blackfriday.el +++ b/ox-blackfriday.el @@ -461,7 +461,21 @@ 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) @@ -469,18 +483,23 @@ contextual information." (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) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 15aacd73..9a595ee0 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -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 @@ -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 diff --git a/test/site/content/posts/nested-lists.md b/test/site/content/posts/nested-lists.md index df19e78a..8c8dcdbb 100644 --- a/test/site/content/posts/nested-lists.md +++ b/test/site/content/posts/nested-lists.md @@ -2,6 +2,7 @@ title = "Nested lists" date = 2017-07-31 tags = ["lists"] +categories = ["upstream"] draft = false +++ @@ -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