forked from mirrors/org-mode
ox: Fix OPTION keyword parsing
* lisp/ox.el (org-export--parse-option-keyword): Handle multiple properties referring to the same option item. * testing/lisp/test-ox.el (test-org-export/parse-option-keyword): Add test.
This commit is contained in:
parent
2c8b0399ca
commit
c708fc0bb8
33
lisp/ox.el
33
lisp/ox.el
|
@ -1339,21 +1339,24 @@ inferior to file-local settings."
|
||||||
Optional argument BACKEND is an export back-end, as returned by,
|
Optional argument BACKEND is an export back-end, as returned by,
|
||||||
e.g., `org-export-create-backend'. It specifies which back-end
|
e.g., `org-export-create-backend'. It specifies which back-end
|
||||||
specific items to read, if any."
|
specific items to read, if any."
|
||||||
(let ((all
|
(let ((line
|
||||||
(mapcar
|
(let ((s 0) alist)
|
||||||
(lambda (o) (cons (nth 2 o) (car o)))
|
(while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" options s)
|
||||||
;; Priority is given to back-end specific options.
|
(setq s (match-end 0))
|
||||||
(append (and backend (org-export-get-all-options backend))
|
(push (cons (match-string 1 options)
|
||||||
org-export-options-alist)))
|
(read (match-string 2 options)))
|
||||||
(start)
|
alist))
|
||||||
plist)
|
alist))
|
||||||
(while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t\n]*" options start)
|
;; Priority is given to back-end specific options.
|
||||||
(setq start (match-end 0))
|
(all (append (and backend (org-export-get-all-options backend))
|
||||||
(let ((property (cdr (assoc-string (match-string 1 options) all t))))
|
org-export-options-alist))
|
||||||
(when property
|
(plist))
|
||||||
(setq plist
|
(when line
|
||||||
(plist-put plist property (read (match-string 2 options)))))))
|
(dolist (entry all plist)
|
||||||
plist))
|
(let ((item (nth 2 entry)))
|
||||||
|
(when item
|
||||||
|
(let ((v (assoc-string item line t)))
|
||||||
|
(when v (setq plist (plist-put plist (car entry) (cdr v)))))))))))
|
||||||
|
|
||||||
(defun org-export--get-subtree-options (&optional backend)
|
(defun org-export--get-subtree-options (&optional backend)
|
||||||
"Get export options in subtree at point.
|
"Get export options in subtree at point.
|
||||||
|
|
|
@ -108,34 +108,62 @@ variable, and communication channel under `info'."
|
||||||
(ert-deftest test-org-export/parse-option-keyword ()
|
(ert-deftest test-org-export/parse-option-keyword ()
|
||||||
"Test reading all standard #+OPTIONS: items."
|
"Test reading all standard #+OPTIONS: items."
|
||||||
(should
|
(should
|
||||||
(equal
|
(let ((options
|
||||||
(org-export--parse-option-keyword
|
(org-export--parse-option-keyword
|
||||||
"H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
|
"H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t \
|
||||||
*:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
|
*:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil \
|
||||||
stat:t title:t")
|
stat:t title:t")))
|
||||||
'(:headline-levels
|
(and (eq (plist-get options :headline-levels) 1)
|
||||||
1 :section-numbers t :preserve-breaks t :time-stamp-file t
|
(eq (plist-get options :section-numbers) t)
|
||||||
:with-archived-trees t :with-author t :with-creator t :with-drawers t
|
(eq (plist-get options :preserve-breaks) t)
|
||||||
:with-email t :with-emphasize t :with-entities t :with-fixed-width t
|
(eq (plist-get options :time-stamp-file) t)
|
||||||
:with-footnotes t :with-priority t :with-special-strings t
|
(eq (plist-get options :with-archived-trees) t)
|
||||||
:with-sub-superscript t :with-toc t :with-tables t :with-tags t
|
(eq (plist-get options :with-author) t)
|
||||||
:with-tasks t :with-timestamps t :with-todo-keywords t
|
(eq (plist-get options :with-drawers) t)
|
||||||
:with-inlinetasks nil :with-statistics-cookies t :with-title t)))
|
(eq (plist-get options :with-email) t)
|
||||||
|
(eq (plist-get options :with-emphasize) t)
|
||||||
|
(eq (plist-get options :with-entities) t)
|
||||||
|
(eq (plist-get options :with-fixed-width) t)
|
||||||
|
(eq (plist-get options :with-footnotes) t)
|
||||||
|
(eq (plist-get options :with-priority) t)
|
||||||
|
(eq (plist-get options :with-special-strings) t)
|
||||||
|
(eq (plist-get options :with-sub-superscript) t)
|
||||||
|
(eq (plist-get options :with-toc) t)
|
||||||
|
(eq (plist-get options :with-tables) t)
|
||||||
|
(eq (plist-get options :with-tags) t)
|
||||||
|
(eq (plist-get options :with-tasks) t)
|
||||||
|
(eq (plist-get options :with-timestamps) t)
|
||||||
|
(eq (plist-get options :with-todo-keywords) t)
|
||||||
|
(eq (plist-get options :with-inlinetasks) nil)
|
||||||
|
(eq (plist-get options :with-statistics-cookies) t)
|
||||||
|
(eq (plist-get options :with-title) t))))
|
||||||
;; Test some special values.
|
;; Test some special values.
|
||||||
(should
|
(should
|
||||||
(equal
|
(let ((options
|
||||||
(org-export--parse-option-keyword
|
(org-export--parse-option-keyword
|
||||||
"arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
|
"arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo \
|
||||||
'(:with-archived-trees
|
num:2 <:active")))
|
||||||
headline :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
|
(and (eq (plist-get options :with-archived-trees) 'headline)
|
||||||
:with-tags not-in-toc :with-tasks todo :section-numbers 2
|
(eq (plist-get options :with-sub-superscript) '{})
|
||||||
:with-timestamps active)))
|
(eq (plist-get options :with-toc) 1)
|
||||||
|
(eq (plist-get options :with-tags) 'not-in-toc)
|
||||||
|
(eq (plist-get options :with-tasks) 'todo)
|
||||||
|
(eq (plist-get options :section-numbers) 2)
|
||||||
|
(eq (plist-get options :with-timestamps) 'active)
|
||||||
|
(equal (plist-get options :with-drawers) '("TEST")))))
|
||||||
;; Test back-end specific values.
|
;; Test back-end specific values.
|
||||||
(should
|
(should
|
||||||
(equal
|
(equal
|
||||||
(org-export--parse-option-keyword
|
(org-export--parse-option-keyword
|
||||||
"opt:t" (org-export-create-backend :options '((:option nil "opt"))))
|
"opt:t" (org-export-create-backend :options '((:option nil "opt"))))
|
||||||
'(:option t))))
|
'(:option t)))
|
||||||
|
;; More than one property can refer to the same option item.
|
||||||
|
(should
|
||||||
|
(equal '(:opt1 t :opt2 t)
|
||||||
|
(org-export--parse-option-keyword
|
||||||
|
"opt:t"
|
||||||
|
(org-export-create-backend
|
||||||
|
:options '((:opt1 nil "opt") (:opt2 nil "opt")))))))
|
||||||
|
|
||||||
(ert-deftest test-org-export/get-inbuffer-options ()
|
(ert-deftest test-org-export/get-inbuffer-options ()
|
||||||
"Test reading all standard export keywords."
|
"Test reading all standard export keywords."
|
||||||
|
|
Loading…
Reference in a new issue