Browse Source

ox: Fix OPTIONS line parsing

* lisp/ox.el (org-export--parse-option-keyword): Fix parsing of items.
* testing/lisp/test-ox.el (test-org-export/parse-option-keyword): Add
  test.
Nicolas Goaziou 10 years ago
parent
commit
c88256c776
2 changed files with 27 additions and 26 deletions
  1. 12 16
      lisp/ox.el
  2. 15 10
      testing/lisp/test-ox.el

+ 12 - 16
lisp/ox.el

@@ -1372,24 +1372,20 @@ inferior to file-local settings."
 Optional argument BACKEND is an export back-end, as returned by,
 e.g., `org-export-create-backend'.  It specifies which back-end
 specific items to read, if any."
-  (let* ((all
+  (let ((all
+	 (mapcar
+	  (lambda (o) (cons (nth 2 o) (car o)))
 	  ;; Priority is given to back-end specific options.
 	  (append (and backend (org-export-get-all-options backend))
-		  org-export-options-alist))
-	 plist)
-    (dolist (option all)
-      (let ((property (car option))
-	    (item (nth 2 option)))
-	(when (and item
-		   (not (plist-member plist property))
-		   (string-match (concat "\\(\\`\\|[ \t]\\)"
-					 (regexp-quote item)
-					 ":\\(([^)\n]+)\\|[^ \t\n\r;,.]*\\)")
-				 options))
-	  (setq plist (plist-put plist
-				 property
-				 (car (read-from-string
-				       (match-string 2 options))))))))
+		  org-export-options-alist)))
+	(start)
+	plist)
+    (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t\n]*" options start)
+      (setq start (match-end 0))
+      (let ((property (cdr (assoc-string (match-string 1 options) all t))))
+	(when property
+	  (setq plist
+		(plist-put plist property (read (match-string 2 options)))))))
     plist))
 
 (defun org-export--get-subtree-options (&optional backend)

+ 15 - 10
testing/lisp/test-ox.el

@@ -114,23 +114,28 @@ variable, and communication channel under `info'."
  *: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")
     '(:headline-levels
-      1 :preserve-breaks t :section-numbers t :time-stamp-file t
+      1 :section-numbers t :preserve-breaks t :time-stamp-file t
       :with-archived-trees t :with-author t :with-creator t :with-drawers t
       :with-email t :with-emphasize t :with-entities t :with-fixed-width t
-      :with-footnotes t :with-inlinetasks nil :with-priority t
-      :with-special-strings t :with-statistics-cookies t :with-sub-superscript t
-      :with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
-      :with-title t :with-todo-keywords t)))
+      :with-footnotes t :with-priority t :with-special-strings t
+      :with-sub-superscript t :with-toc t :with-tables t :with-tags t
+      :with-tasks t :with-timestamps t :with-todo-keywords t
+      :with-inlinetasks nil :with-statistics-cookies t :with-title t)))
   ;; Test some special values.
   (should
    (equal
     (org-export--parse-option-keyword
      "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
-    '( :section-numbers
-       2
-       :with-archived-trees headline :with-drawers ("TEST")
-       :with-sub-superscript {} :with-toc 1 :with-tags not-in-toc
-       :with-tasks todo :with-timestamps active))))
+    '(:with-archived-trees
+      headline :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
+      :with-tags not-in-toc :with-tasks todo :section-numbers 2
+      :with-timestamps active)))
+  ;; Test back-end specific values.
+  (should
+   (equal
+    (org-export--parse-option-keyword
+     "opt:t" (org-export-create-backend :options '((:option nil "opt"))))
+    '(:option t))))
 
 (ert-deftest test-org-export/get-inbuffer-options ()
   "Test reading all standard export keywords."