ox-ascii: Fix descriptive lists

* lisp/ox-ascii.el (org-ascii-quote-margin): Update docstring.
(org-ascii--current-text-width): Properly handle width of text within
nested plain-list items.
(org-ascii-item): Always start a new line for description contents.
Indent them by `org-ascii-quote-margin' characters.
This commit is contained in:
Nicolas Goaziou 2017-11-06 14:27:45 +01:00
parent 271e58f2dd
commit 7000ed9ee0
1 changed files with 93 additions and 97 deletions

View File

@ -177,7 +177,8 @@ Inner margin is applied between each headline."
(defcustom org-ascii-quote-margin 6
"Width of margin used for quoting text, in characters.
This margin is applied on both sides of the text."
This margin is applied on both sides of the text. It is also
applied on the left side of contents in descriptive lists."
:group 'org-export-ascii
:version "24.4"
:package-version '(Org . "8.0")
@ -597,33 +598,23 @@ INFO is a plist used as a communication channel."
'item))))
genealogy)
(plist-get info :ascii-list-margin))
;; Text width within a plain-list is restricted by
;; indentation of current item. If that's the case,
;; compute it with the help of `:structure' property from
;; parent item, if any.
(let ((item
(if (eq (org-element-type element) 'item) element
(cl-find-if (lambda (parent)
(eq (org-element-type parent) 'item))
genealogy))))
(if (not item) 0
;; Compute indentation offset of the current item,
;; that is the sum of the difference between its
;; indentation and the indentation of the top item in
;; the list and current item bullet's length. Also
;; remove checkbox length, and tag length (for
;; description lists) or bullet length.
(let ((struct (org-element-property :structure item))
(beg-item (org-element-property :begin item)))
(+ (- (org-list-get-ind beg-item struct)
(org-list-get-ind
(org-list-get-top-point struct) struct))
(string-width (or (org-ascii--checkbox item info)
""))
;; Compute indentation offset due to current list. It is
;; `org-ascii-quote-margin' per descriptive item in the
;; genealogy, bullet's length otherwise.
(let ((indentation 0))
(dolist (e genealogy)
(cond
((not (eq 'item (org-element-type e))))
((eq (org-element-property :type (org-export-get-parent e))
'descriptive)
(cl-incf indentation org-ascii-quote-margin))
(t
(cl-incf indentation
(+ (string-width
(or (org-ascii--checkbox e info) ""))
(string-width
(let ((tag (org-element-property :tag item)))
(if tag (org-export-data tag info)
(org-element-property :bullet item))))))))))))))
(org-element-property :bullet e)))))))
indentation)))))))
(defun org-ascii--current-justification (element)
"Return expected justification for ELEMENT's contents.
@ -1458,17 +1449,17 @@ contextual information."
(bullet
;; First parent of ITEM is always the plain-list. Get
;; `:type' property from it.
(org-list-bullet-string
(pcase list-type
(`descriptive
(concat checkbox
(org-export-data (org-element-property :tag item) info)
": "))
(org-export-data (org-element-property :tag item)
info)))
(`ordered
;; Return correct number for ITEM, paying attention to
;; counters.
(let* ((struct (org-element-property :structure item))
(bul (org-element-property :bullet item))
(bul (org-list-bullet-string
(org-element-property :bullet item)))
(num (number-to-string
(car (last (org-list-get-item-number
(org-element-property :begin item)
@ -1476,22 +1467,27 @@ contextual information."
(org-list-prevs-alist struct)
(org-list-parents-alist struct)))))))
(replace-regexp-in-string "[0-9]+" num bul)))
(_ (let ((bul (org-element-property :bullet item)))
(_ (let ((bul (org-list-bullet-string
(org-element-property :bullet item))))
;; Change bullets into more visible form if UTF-8 is active.
(if (not utf8p) bul
(replace-regexp-in-string
"-" ""
(replace-regexp-in-string
"+" ""
(replace-regexp-in-string "*" "" bul))))))))))
(replace-regexp-in-string "*" "" bul))))))))
(indentation (if (eq list-type 'descriptive) org-ascii-quote-margin
(string-width bullet))))
(concat
bullet
(unless (eq list-type 'descriptive) checkbox)
checkbox
;; Contents: Pay attention to indentation. Note: check-boxes are
;; already taken care of at the paragraph level so they don't
;; interfere with indentation.
(let ((contents (org-ascii--indent-string contents (string-width bullet))))
(if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
(let ((contents (org-ascii--indent-string contents indentation)))
(if (and (eq (org-element-type (car (org-element-contents item)))
'paragraph)
(not (eq list-type 'descriptive)))
(org-trim contents)
(concat "\n" contents))))))